Skip to content

Commit cc78666

Browse files
author
Semih KEŞKEK
authored
Merge pull request #1 from msusur/master
Gigantic Changes
2 parents cfcd8a9 + 27ca338 commit cc78666

17 files changed

Lines changed: 434 additions & 90 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
dist/

.npmignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
bower.json
2-
tsconfig.json
2+
tsconfig.json
3+
npm-debug.log

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
## v1.1.2
2+
Added unit tests for the service and project restructure updated to use the benefits of webpack and bundling.
13

24
## v1.1.1
35
Recovery fix and added interfaces.
@@ -33,7 +35,7 @@ declare class PubSubService{
3335
```
3436
-------
3537
## v1.0.0
36-
A simple publisher/subscriber service.
38+
A simple publisher/subscriber service.
3739

3840
### Class Overview
3941
```typescript

README.md

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,21 @@
22

33
A simple publisher/subscriber service.
44

5+
## Contributers
6+
7+
- [Semih KEŞKEK](http://github.com/sqlProvider)
8+
- [Mert SUSUR](http://github.com/msusur)
9+
510
## Usage
611
- Import service in your codes or download via npm or bower.
712

813
`npm i --save angular2-pubsub` | `bower i --save angular2-pubsub`
914

10-
- Add service to App Module providers.
15+
- Add module bundle to imports in your application.
1116
```typescript
1217
...
1318

14-
import { EventDispatcherService } from './path/to/service/angular2-pubsub.service'; // <= HERE
19+
import { PubSubModule } from 'angular2-pubsub'; // <= HERE
1520

1621
@NgModule({
1722
declarations: [
@@ -22,9 +27,10 @@ declarations: [
2227
imports: [
2328
BrowserModule,
2429
FormsModule,
25-
HttpModule
30+
HttpModule,
31+
PubSubModule.forRoot() // <= AND HERE
2632
],
27-
providers: [EventDispatcherService], // <= AND HERE
33+
providers: [],
2834
bootstrap: [RootComponent]
2935
})
3036

@@ -37,7 +43,7 @@ bootstrap: [RootComponent]
3743
#### Class Overview
3844

3945
```typescript
40-
declare class PubSubService{
46+
declare class PubSubService {
4147
private events: Object;
4248
$pub(event: string, eventObject?: any): void;
4349
$sub(): undefined;
@@ -99,4 +105,15 @@ this.closeSidenavSub = this.pubsub.$sub('pleaseCloseSidenav').subscribe((from) =
99105
});
100106

101107
// => 0
102-
```
108+
```
109+
110+
## Build the source
111+
112+
Follow the steps to run the tests and build the source code.
113+
```sh
114+
npm install
115+
npm test
116+
npm run build
117+
```
118+
Commands above will generate the ready to use bundles under the `./dist` folder.
119+

angular2-pubsub.service.ts

Lines changed: 0 additions & 55 deletions
This file was deleted.

bower.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
{
22
"name": "angular2-pubsub",
33
"description": "Pub/Sub service for Angular 2",
4-
"version": "1.1.1",
5-
"main": "",
4+
"version": "1.1.2",
5+
"main": "./umd/angular2-pubsub.js",
66
"authors": [
7-
"Semih KEŞKEK"
7+
"Semih KEŞKEK",
8+
"Mert SUSUR"
89
],
910
"license": "ISC",
1011
"keywords": [

karma-test-runner.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
2+
Error.stackTraceLimit = Infinity;
3+
4+
require('reflect-metadata');
5+
require('zone.js/dist/zone');;
6+
require('zone.js/dist/long-stack-trace-zone');
7+
require('zone.js/dist/async-test');
8+
require('zone.js/dist/fake-async-test');
9+
require('zone.js/dist/sync-test');
10+
require('zone.js/dist/proxy');
11+
require('zone.js/dist/jasmine-patch');
12+
13+
var testing = require('@angular/core/testing');
14+
var browser = require('@angular/platform-browser-dynamic/testing');
15+
16+
testing.TestBed.initTestEnvironment(
17+
browser.BrowserDynamicTestingModule,
18+
browser.platformBrowserDynamicTesting()
19+
);
20+
21+
Object.assign(global, testing);
22+
23+
var testContext = require.context('./src', true, /\.spec\.ts/);
24+
25+
function requireAll(requireContext) {
26+
return requireContext.keys().map(requireContext);
27+
}
28+
29+
var modules = requireAll(testContext);

karma.conf.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module.exports = function (config) {
2+
config.set({
3+
browsers: ['PhantomJS'],
4+
frameworks: ['jasmine'],
5+
reporters: ['mocha'],
6+
singleRun: true,
7+
preprocessors: { './karma-test-runner.js': ['webpack', 'sourcemap'] },
8+
files: [
9+
{ pattern: 'node_modules/babel-polyfill/browser.js', instrument: false },
10+
{ pattern: './karma-test-runner.js', watched: false }
11+
],
12+
webpack: require('./webpack.config.test.js'),
13+
14+
webpackServer: { noInfo: true }
15+
});
16+
};

package.json

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,94 @@
11
{
2-
"name": "angular2-pubsub",
3-
"version": "1.1.1",
4-
"description": "Pub/Sub service for Angular 2",
5-
"repository": {
6-
"type": "git",
7-
"url": "git+https://github.com/sqlProvider/angular2-pubsub.git"
8-
},
9-
"keywords": [
10-
"Angular2",
11-
"pubsub",
12-
"angular2-service"
13-
],
14-
"author": {
15-
"name": "Semih KEŞKEK",
16-
"email": "keskeksmh@gmail.com"
17-
},
18-
"license": "ISC",
19-
"bugs": {
20-
"url": "https://github.com/sqlProvider/angular2-pubsub/issues"
21-
},
22-
"homepage": "https://github.com/sqlProvider/angular2-pubsub#readme"
2+
"name": "angular2-pubsub",
3+
"version": "1.1.2",
4+
"description": "Pub/Sub service for Angular 2",
5+
"main": "./umd/angular2-pubsub.js",
6+
"module": "./esm/src/index.js",
7+
"typings": "./esm/src/index.d.ts",
8+
"repository": {
9+
"type": "git",
10+
"url": "git+https://github.com/sqlProvider/angular2-pubsub.git"
11+
},
12+
"scripts": {
13+
"test": "karma start",
14+
"clean": "rm -rf dist",
15+
"build-umd": "webpack --config webpack.config.umd.js",
16+
"build-angular": "ngc -p tsconfig-ngc.json",
17+
"copy-package-info": "cp ./package.json ./dist/package.json && cp ./bower.json ./dist/bower.json",
18+
"build": "npm run clean && npm run build-umd && npm run build-angular && npm run copy-package-info"
19+
},
20+
"keywords": [
21+
"Angular2",
22+
"pubsub",
23+
"angular2-service"
24+
],
25+
"author": {
26+
"name": "Semih KEŞKEK",
27+
"email": "keskeksmh@gmail.com"
28+
},
29+
"contributors": [
30+
{
31+
"name": "Mert Susur",
32+
"email": "mail@mertsusur.com",
33+
"url": "http://github.com/msusur"
34+
}
35+
],
36+
"license": "ISC",
37+
"bugs": {
38+
"url": "https://github.com/sqlProvider/angular2-pubsub/issues"
39+
},
40+
"homepage": "https://github.com/sqlProvider/angular2-pubsub#readme",
41+
"dependencies": {
42+
"@angular/common": "^2.4.7",
43+
"@angular/compiler": "^2.4.7",
44+
"@angular/core": "^2.4.7",
45+
"@angular/forms": "^2.4.7",
46+
"@angular/platform-browser": "^2.4.7",
47+
"jasmine-core": "^2.5.2",
48+
"rxjs": "^5.1.0",
49+
"ts-helpers": "^1.1.2",
50+
"zone.js": "^0.7.6"
51+
},
52+
"devDependencies": {
53+
"@angular/compiler-cli": "^2.4.7",
54+
"@angular/platform-browser-dynamic": "^2.4.7",
55+
"@types/es6-shim": "^0.31.32",
56+
"@types/jasmine": "^2.5.41",
57+
"@types/node": "^7.0.5",
58+
"awesome-typescript-loader": "^3.0.4-rc.0",
59+
"babel-polyfill": "^6.22.0",
60+
"chai": "^3.5.0",
61+
"codelyzer": "^2.0.0",
62+
"commitizen": "^2.9.5",
63+
"compression-webpack-plugin": "^0.3.2",
64+
"extract-text-webpack-plugin": "^1.0.1",
65+
"imports-loader": "^0.7.0",
66+
"karma": "^1.4.1",
67+
"karma-chrome-launcher": "^2.0.0",
68+
"karma-coverage": "^1.1.1",
69+
"karma-jasmine": "^1.1.0",
70+
"karma-mocha-reporter": "^2.2.2",
71+
"karma-phantomjs-launcher": "^1.0.2",
72+
"karma-remap-istanbul": "^0.4.0",
73+
"karma-sourcemap-loader": "^0.3.7",
74+
"karma-typescript": "^2.1.6",
75+
"karma-webpack": "^1.8.1",
76+
"phantomjs-prebuilt": "^2.1.7",
77+
"rxjs": "^5.0.1",
78+
"sinon": "^1.17.4",
79+
"sinon-chai": "^2.8.0",
80+
"sourcemap-istanbul-instrumenter-loader": "^0.2.0",
81+
"standard-version": "^4.0.0",
82+
"stylelint-webpack-plugin": "^0.5.1",
83+
"ts-loader": "^1.3.3",
84+
"tslint": "^4.0.2",
85+
"tslint-loader": "^3.3.0",
86+
"typedoc": "^0.5.0",
87+
"typescript": "^2.1.6",
88+
"validate-commit-msg": "^2.8.0",
89+
"webpack": "^1.13.0",
90+
"webpack-dev-server": "^1.16.1",
91+
"webpack-fix-default-import-plugin": "^1.0.1",
92+
"zone.js": "^0.7.4"
93+
}
2394
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* tslint:disable:no-unused-variable */
2+
3+
import { PubSubService } from './angular2-pubsub.service';
4+
import { Observable, Subscriber } from 'rxjs';
5+
6+
describe('PubSubService', (): void => {
7+
let pubService: PubSubService;
8+
9+
beforeEach(() => {
10+
pubService = new PubSubService();
11+
});
12+
13+
describe('$sub', (): void => {
14+
it('should throw an error when event is falsy', (): void => {
15+
expect(pubService.$sub.bind(undefined)).toThrow();
16+
});
17+
18+
it('should return an observable when there is no callback', (): void => {
19+
let result: any = pubService.$sub('test');
20+
expect(result instanceof Observable).toBeTruthy();
21+
});
22+
23+
it('should return a subscriber when there is a callback specified', (): void => {
24+
let result: any = pubService.$sub('test', (v: any): void => {
25+
'';
26+
});
27+
expect(result instanceof Subscriber).toBeTruthy();
28+
});
29+
});
30+
31+
describe('$pub', (): void => {
32+
it('should throw an error when event is falsy', (): void => {
33+
expect(pubService.$pub.bind(undefined)).toThrow();
34+
});
35+
36+
it('should throw an error when event is not registered', (): void => {
37+
expect(pubService.$pub.bind('not-registered')).toThrow();
38+
});
39+
40+
it('should publish with parameters if the event is registered', (): void => {
41+
let subscriberEventSpy: jasmine.Spy = jasmine.createSpy('subscriberEvent');
42+
pubService.$sub('new-event', subscriberEventSpy);
43+
44+
pubService.$pub('new-event', 'foo');
45+
46+
expect(subscriberEventSpy).toHaveBeenCalledWith('foo');
47+
});
48+
});
49+
});

0 commit comments

Comments
 (0)