react-rxjs-event-emitter upgraded to SPFx version 1.7.0 (#721)

This commit is contained in:
Velin Georgiev 2018-12-19 07:19:53 +00:00 committed by Vesa Juvonen
parent a261876295
commit 9152d8b655
24 changed files with 5654 additions and 4862 deletions

View File

@ -1,8 +1,12 @@
{ {
"@microsoft/generator-sharepoint": { "@microsoft/generator-sharepoint": {
"version": "1.4.1", "version": "1.7.0",
"libraryName": "react-rxjs-event-emitter", "libraryName": "react-rxjs-event-emitter",
"libraryId": "323ec3b8-b5de-4184-99a6-7e0f9c276412", "libraryId": "323ec3b8-b5de-4184-99a6-7e0f9c276412",
"environment": "spo" "environment": "spo",
"componentType": "webpart",
"packageManager": "npm",
"isCreatingSolution": true,
"isDomainIsolated": false
} }
} }

View File

@ -7,7 +7,7 @@ This sample shows how we can use the [ReactiveX (RxJs)](http://reactivex.io/) li
![SPFx ReactiveX (RxJs) Event Emitter Sample](./assets/spfx-event-emitter.gif) ![SPFx ReactiveX (RxJs) Event Emitter Sample](./assets/spfx-event-emitter.gif)
## Used SharePoint Framework Version ## Used SharePoint Framework Version
![drop](https://img.shields.io/badge/drop-1.4.1-green.svg) ![drop](https://img.shields.io/badge/drop-1.7.0-green.svg)
## Applies to ## Applies to
@ -31,6 +31,7 @@ Version|Date|Comments
-------|----|-------- -------|----|--------
0.0.1|August 22, 2017 | Initial commit 0.0.1|August 22, 2017 | Initial commit
0.0.2|April 20, 2018 | Updated to SPFx v1.4.1 0.0.2|April 20, 2018 | Updated to SPFx v1.4.1
0.0.3|December 10, 2018 | Updated to SPFx v1.7.0
## Disclaimer ## Disclaimer
**THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.** **THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.**
@ -42,7 +43,6 @@ Version|Date|Comments
- Clone this repository. - Clone this repository.
- Open the command line, navigate to the web part folder and execute: - Open the command line, navigate to the web part folder and execute:
- `npm i` - `npm i`
- `gulp test` (optional)
- `gulp serve` - `gulp serve`
## Features ## Features
@ -53,7 +53,6 @@ This Web Part illustrates the following concepts on top of the SharePoint Framew
- Using Office UI Fabric React styles for building user experience consistent with SharePoint and Office. - Using Office UI Fabric React styles for building user experience consistent with SharePoint and Office.
- The use the ReactiveX (RxJs) Event Emitter to broadcast messages (events). - The use the ReactiveX (RxJs) Event Emitter to broadcast messages (events).
- The use the ReactiveX (RxJs) Event Emitter to subscribe and receive broadcasted messages (events). - The use the ReactiveX (RxJs) Event Emitter to subscribe and receive broadcasted messages (events).
- Unit tests including spies, mocks and faking class methods and properties.
## Making the RxJsEventEmitter external SPFx library. ## Making the RxJsEventEmitter external SPFx library.

View File

@ -1,5 +1,5 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx-build/config.2.0.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/config.2.0.schema.json",
"version": "2.0", "version": "2.0",
"bundles": { "bundles": {
"rxjseventemitter": { "rxjseventemitter": {

View File

@ -1,4 +1,4 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx-build/copy-assets.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/copy-assets.schema.json",
"deployCdnPath": "temp/deploy" "deployCdnPath": "temp/deploy"
} }

View File

@ -1,5 +1,5 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx-build/deploy-azure-storage.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/deploy-azure-storage.schema.json",
"workingDir": "./temp/deploy/", "workingDir": "./temp/deploy/",
"account": "<!-- STORAGE ACCOUNT NAME -->", "account": "<!-- STORAGE ACCOUNT NAME -->",
"container": "react-rxjs-event-emitter", "container": "react-rxjs-event-emitter",

View File

@ -1,10 +1,11 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx-build/package-solution.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/package-solution.schema.json",
"solution": { "solution": {
"name": "react-rxjs-event-emitter-client-side-solution", "name": "react-rxjs-event-emitter-client-side-solution",
"id": "323ec3b8-b5de-4184-99a6-7e0f9c276412", "id": "323ec3b8-b5de-4184-99a6-7e0f9c276412",
"version": "1.0.0.0", "version": "1.0.0.0",
"includeClientSideAssets": true "includeClientSideAssets": true,
"isDomainIsolated": false
}, },
"paths": { "paths": {
"zippedPackage": "solution/react-rxjs-event-emitter.sppkg" "zippedPackage": "solution/react-rxjs-event-emitter.sppkg"

View File

@ -1,5 +1,5 @@
{ {
"$schema": "https://dev.office.com/json-schemas/core-build/serve.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/core-build/serve.schema.json",
"port": 4321, "port": 4321,
"initialPage": "https://localhost:5432/workbench", "initialPage": "https://localhost:5432/workbench",
"https": true, "https": true,

View File

@ -1,45 +0,0 @@
{
"$schema": "https://dev.office.com/json-schemas/core-build/tslint.schema.json",
// Display errors as warnings
"displayAsWarning": true,
// The TSLint task may have been configured with several custom lint rules
// before this config file is read (for example lint rules from the tslint-microsoft-contrib
// project). If true, this flag will deactivate any of these rules.
"removeExistingRules": true,
// When true, the TSLint task is configured with some default TSLint "rules.":
"useDefaultConfigAsBase": false,
// Since removeExistingRules=true and useDefaultConfigAsBase=false, there will be no lint rules
// which are active, other than the list of rules below.
"lintConfig": {
// Opt-in to Lint rules which help to eliminate bugs in JavaScript
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-case": true,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"valid-typeof": true,
"variable-name": false,
"whitespace": false
}
}
}

View File

@ -1,4 +1,4 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx-build/write-manifests.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx-build/write-manifests.schema.json",
"cdnBasePath": "<!-- PATH TO CDN -->" "cdnBasePath": "<!-- PATH TO CDN -->"
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +1,35 @@
{ {
"name": "react-rxjs-event-emitter", "name": "react-rxjs-event-emitter",
"version": "0.0.2", "version": "0.0.3",
"private": true, "private": true,
"engines": { "engines": {
"node": ">=0.10.0" "node": ">=0.10.0"
}, },
"dependencies": { "dependencies": {
"react": "15.6.2", "@microsoft/sp-core-library": "1.7.0",
"react-dom": "15.6.2", "@microsoft/sp-lodash-subset": "1.7.0",
"@types/react": "15.6.6", "@microsoft/sp-office-ui-fabric-core": "1.7.0",
"@types/react-dom": "15.5.6", "@microsoft/sp-webpart-base": "1.7.0",
"@microsoft/sp-core-library": "~1.4.1", "@types/es6-promise": "0.0.33",
"@microsoft/sp-webpart-base": "~1.4.1", "@types/react": "16.4.2",
"@microsoft/sp-lodash-subset": "~1.4.1", "@types/react-dom": "16.0.5",
"@microsoft/sp-office-ui-fabric-core": "~1.4.1",
"@types/rx-lite": "4.0.5", "@types/rx-lite": "4.0.5",
"rx-lite": "^4.0.5" "@types/webpack-env": "1.13.1",
"react": "16.3.2",
"react-dom": "16.3.2",
"rx-lite": "4.0.8"
}, },
"devDependencies": { "devDependencies": {
"@microsoft/sp-build-web": "~1.4.1", "@microsoft/sp-build-web": "1.7.0",
"@microsoft/sp-module-interfaces": "~1.4.1", "@microsoft/sp-module-interfaces": "1.7.0",
"@microsoft/sp-webpart-workbench": "~1.4.1", "@microsoft/sp-webpart-workbench": "1.7.0",
"gulp": "~3.9.1", "@types/chai": "3.4.34",
"@types/chai": ">=3.4.34 <3.6.0", "@types/mocha": "2.2.38",
"@types/mocha": ">=2.2.33 <2.6.0",
"ajv": "~5.2.2", "ajv": "~5.2.2",
"enzyme": "^2.9.1", "enzyme": "^2.9.1",
"react-addons-test-utils": "^15.6.0" "gulp": "~3.9.1",
"react-addons-test-utils": "^15.6.0",
"tslint-microsoft-contrib": "5.0.0"
}, },
"scripts": { "scripts": {
"build": "gulp bundle", "build": "gulp bundle",

View File

@ -0,0 +1,2 @@
// A file is required to be in the root of the /src directory by the TypeScript compiler

View File

@ -1,5 +1,5 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "d0c6977d-b995-46ff-a246-14ff43495e0e", "id": "d0c6977d-b995-46ff-a246-14ff43495e0e",
"alias": "BroadcasterWebPart", "alias": "BroadcasterWebPart",
"componentType": "WebPart", "componentType": "WebPart",

View File

@ -1,84 +0,0 @@
/// <reference types="mocha" />
/// <reference types="sinon" />
import * as React from 'react';
import { assert } from 'chai';
import { mount, ReactWrapper } from 'enzyme';
import Broadcaster from "../components/Broadcaster";
import { EventData } from "../../../libraries/rxJsEventEmitter/EventData";
import { RxJsEventEmitter } from "../../../libraries/rxJsEventEmitter/RxJsEventEmitter";
declare const sinon: sinon.SinonStatic;
describe('BroadcasterWebPart', () => {
let rxJsEventEmitterEmitSpy: sinon.SinonSpy;
let broadcastDataSpy: sinon.SinonSpy;
let broadcaster: ReactWrapper<Broadcaster, any>;
beforeEach(() => {
// create spies so we test if event is triggered.
rxJsEventEmitterEmitSpy = sinon.spy((RxJsEventEmitter.prototype as any), "emit");
broadcastDataSpy = sinon.spy((Broadcaster.prototype as any), "broadcastData");
// mount the Broadcaster so we can test it.
broadcaster = mount(<Broadcaster />);
});
afterEach(() => {
broadcaster.unmount();
rxJsEventEmitterEmitSpy.restore();
broadcastDataSpy.restore();
});
it('should broadcast message with number 1', () => {
let currentEventNumber: number = 1;
// we click on the button to raise new event.
broadcaster.find("#BroadcastButton").simulate("click");
// check if event is broadcasted.
assert(broadcastDataSpy.calledOnce === true);
assert(broadcaster.state().eventNumber === currentEventNumber);
assert(rxJsEventEmitterEmitSpy.calledOnce === true);
assert(rxJsEventEmitterEmitSpy.calledWith("myCustomEvent:start",
{ currentNumber: currentEventNumber } as EventData) === true);
});
it('should broadcast message with number 2', () => {
let currentEventNumber: number = 2;
broadcaster.find("#BroadcastButton").simulate("click");
// broadcast second event and check the data send.
broadcaster.find("#BroadcastButton").simulate("click");
assert(broadcastDataSpy.calledTwice === true);
assert(broadcaster.state().eventNumber === currentEventNumber);
assert(rxJsEventEmitterEmitSpy.calledTwice === true);
assert(rxJsEventEmitterEmitSpy.calledWith("myCustomEvent:start",
{ currentNumber: currentEventNumber } as EventData) === true);
});
it('should fail on wrong message', () => {
let currentEventNumber: number = 3;
let wrongEventNumber: number = 99999;
broadcaster.find("#BroadcastButton").simulate("click");
// broadcast second event and check the data send.
broadcaster.find("#BroadcastButton").simulate("click");
// broadcast third event and check the data send.
broadcaster.find("#BroadcastButton").simulate("click");
assert(broadcastDataSpy.calledThrice === true);
assert(broadcaster.state().eventNumber === currentEventNumber);
assert(rxJsEventEmitterEmitSpy.calledThrice === true);
assert(rxJsEventEmitterEmitSpy.calledWith("myCustomEvent:start",
{ currentNumber: wrongEventNumber } as EventData) === false);
});
});

View File

@ -1,5 +1,5 @@
{ {
"$schema": "https://dev.office.com/json-schemas/spfx/client-side-web-part-manifest.schema.json", "$schema": "https://developer.microsoft.com/json-schemas/spfx/client-side-web-part-manifest.schema.json",
"id": "891b997e-67da-4da3-a6e1-3caf8bb264be", "id": "891b997e-67da-4da3-a6e1-3caf8bb264be",
"alias": "ReceiverWebPart", "alias": "ReceiverWebPart",
"componentType": "WebPart", "componentType": "WebPart",

View File

@ -1,52 +0,0 @@
/// <reference types="mocha" />
/// <reference types="sinon" />
import * as React from 'react';
import { assert } from 'chai';
import { mount, ReactWrapper } from 'enzyme';
import Receiver from "../components/Receiver";
import { EventData } from "../../../libraries/rxJsEventEmitter/EventData";
import { RxJsEventEmitter } from "../../../libraries/rxJsEventEmitter/RxJsEventEmitter";
declare const sinon: sinon.SinonStatic;
describe('ReceiverWebPart', () => {
let rxJsEventEmitterOnSpy: sinon.SinonSpy;
let receivedEventSpy: sinon.SinonSpy;
let receiver: ReactWrapper<Receiver, any>;
let eventEmitter: RxJsEventEmitter = RxJsEventEmitter.getInstance();
beforeEach(() => {
// create spies so we test if event is triggered.
rxJsEventEmitterOnSpy = sinon.spy(RxJsEventEmitter.prototype, "on");
receivedEventSpy = sinon.spy(Receiver.prototype, "receivedEvent");
// mount the Receiver so we can test it.
receiver = mount(<Receiver />);
});
afterEach(() => {
receiver.unmount();
rxJsEventEmitterOnSpy.restore();
receivedEventSpy.restore();
});
it('should Receiver be subscribed by event name', () => {
assert(rxJsEventEmitterOnSpy.calledOnce === true);
assert(rxJsEventEmitterOnSpy.calledWith("myCustomEvent:start", sinon.match.any) === true);
});
it('should Receive an event and call the receivedEvent function', () => {
let data: EventData = { currentNumber: 1 };
// emit the data so we can test if it has been received by the receivedEvent function.
eventEmitter.emit("myCustomEvent:start", data);
assert(receivedEventSpy.calledOnce === true);
assert(receivedEventSpy.calledWith(data) === true);
});
});

View File

@ -0,0 +1,47 @@
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.2/MicrosoftTeams.schema.json",
"manifestVersion": "1.2",
"packageName": "Broadcaster",
"id": "d0c6977d-b995-46ff-a246-14ff43495e0e",
"version": "0.1",
"developer": {
"name": "SPFx + Teams Dev",
"websiteUrl": "https://products.office.com/en-us/sharepoint/collaboration",
"privacyUrl": "https://privacy.microsoft.com/en-us/privacystatement",
"termsOfUseUrl": "https://www.microsoft.com/en-us/servicesagreement"
},
"name": {
"short": "Broadcaster"
},
"description": {
"short": "Broadcasts an event to a channel",
"full": "Broadcasts an event to a channel"
},
"icons": {
"outline": "tab20x20.png",
"color": "tab96x96.png"
},
"accentColor": "#004578",
"configurableTabs": [
{
"configurationUrl": "https://{teamSiteDomain}{teamSitePath}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest={teamSitePath}/_layouts/15/teamshostedapp.aspx%3FopenPropertyPane=true%26teams%26componentId=d0c6977d-b995-46ff-a246-14ff43495e0e",
"canUpdateConfiguration": true,
"scopes": [
"team"
]
}
],
"validDomains": [
"*.login.microsoftonline.com",
"*.sharepoint.com",
"*.sharepoint-df.com",
"spoppe-a.akamaihd.net",
"spoprod-a.akamaihd.net",
"resourceseng.blob.core.windows.net",
"msft.spoppe.com"
],
"webApplicationInfo": {
"resource": "https://{teamSiteDomain}",
"id": "00000003-0000-0ff1-ce00-000000000000"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,47 @@
{
"$schema": "https://developer.microsoft.com/en-us/json-schemas/teams/v1.2/MicrosoftTeams.schema.json",
"manifestVersion": "1.2",
"packageName": "Receiver",
"id": "891b997e-67da-4da3-a6e1-3caf8bb264be",
"version": "0.1",
"developer": {
"name": "SPFx + Teams Dev",
"websiteUrl": "https://products.office.com/en-us/sharepoint/collaboration",
"privacyUrl": "https://privacy.microsoft.com/en-us/privacystatement",
"termsOfUseUrl": "https://www.microsoft.com/en-us/servicesagreement"
},
"name": {
"short": "Receiver"
},
"description": {
"short": "Receives events from the broadcaster web part",
"full": "Receives events from the broadcaster web part"
},
"icons": {
"outline": "tab20x20.png",
"color": "tab96x96.png"
},
"accentColor": "#004578",
"configurableTabs": [
{
"configurationUrl": "https://{teamSiteDomain}{teamSitePath}/_layouts/15/TeamsLogon.aspx?SPFX=true&dest={teamSitePath}/_layouts/15/teamshostedapp.aspx%3FopenPropertyPane=true%26teams%26componentId=891b997e-67da-4da3-a6e1-3caf8bb264be",
"canUpdateConfiguration": true,
"scopes": [
"team"
]
}
],
"validDomains": [
"*.login.microsoftonline.com",
"*.sharepoint.com",
"*.sharepoint-df.com",
"spoppe-a.akamaihd.net",
"spoprod-a.akamaihd.net",
"resourceseng.blob.core.windows.net",
"msft.spoppe.com"
],
"webApplicationInfo": {
"resource": "https://{teamSiteDomain}",
"id": "00000003-0000-0ff1-ce00-000000000000"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 933 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -2,12 +2,14 @@
"compilerOptions": { "compilerOptions": {
"target": "es5", "target": "es5",
"forceConsistentCasingInFileNames": true, "forceConsistentCasingInFileNames": true,
"module": "commonjs", "module": "esnext",
"jsx": "react", "jsx": "react",
"declaration": true, "declaration": true,
"sourceMap": true, "sourceMap": true,
"experimentalDecorators": true, "experimentalDecorators": true,
"skipLibCheck": true, "skipLibCheck": true,
"outDir": "lib",
"moduleResolution": "node",
"typeRoots": [ "typeRoots": [
"./node_modules/@types", "./node_modules/@types",
"./node_modules/@microsoft" "./node_modules/@microsoft"
@ -21,5 +23,12 @@
"dom", "dom",
"es2015.collection" "es2015.collection"
] ]
} },
"include": [
"src/**/*.ts"
],
"exclude": [
"node_modules",
"lib"
]
} }

View File

@ -1,3 +1,31 @@
{ {
"rulesDirectory": "./config" "rulesDirectory": [],
"rules": {
"class-name": false,
"export-name": false,
"forin": false,
"label-position": false,
"member-access": true,
"no-arg": false,
"no-console": false,
"no-construct": false,
"no-duplicate-variable": true,
"no-eval": false,
"no-function-expression": true,
"no-internal-module": true,
"no-shadowed-variable": true,
"no-switch-case-fall-through": true,
"no-unnecessary-semicolons": true,
"no-unused-expression": true,
"no-use-before-declare": true,
"no-with-statement": true,
"semicolon": true,
"trailing-comma": false,
"typedef": false,
"typedef-whitespace": false,
"use-named-parameter": true,
"variable-name": false,
"whitespace": false
},
"extends": "@microsoft/sp-tslint-rules/base-tslint.json"
} }