Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules/
dist/
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
bower.json
tsconfig.json
tsconfig.json
npm-debug.log
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## v1.1.2
Added unit tests for the service and project restructure updated to use the benefits of webpack and bundling.

## v1.1.1
Recovery fix and added interfaces.
Expand Down Expand Up @@ -33,7 +35,7 @@ declare class PubSubService{
```
-------
## v1.0.0
A simple publisher/subscriber service.
A simple publisher/subscriber service.

### Class Overview
```typescript
Expand Down
29 changes: 23 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,21 @@

A simple publisher/subscriber service.

## Contributers

- [Semih KEŞKEK](http://github.com/sqlProvider)
- [Mert SUSUR](http://github.com/msusur)

## Usage
- Import service in your codes or download via npm or bower.

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

- Add service to App Module providers.
- Add module bundle to imports in your application.
```typescript
...

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

@NgModule({
declarations: [
Expand All @@ -22,9 +27,10 @@ declarations: [
imports: [
BrowserModule,
FormsModule,
HttpModule
HttpModule,
PubSubModule.forRoot() // <= AND HERE
],
providers: [EventDispatcherService], // <= AND HERE
providers: [],
bootstrap: [RootComponent]
})

Expand All @@ -37,7 +43,7 @@ bootstrap: [RootComponent]
#### Class Overview

```typescript
declare class PubSubService{
declare class PubSubService {
private events: Object;
$pub(event: string, eventObject?: any): void;
$sub(): undefined;
Expand Down Expand Up @@ -99,4 +105,15 @@ this.closeSidenavSub = this.pubsub.$sub('pleaseCloseSidenav').subscribe((from) =
});

// => 0
```
```

## Build the source

Follow the steps to run the tests and build the source code.
```sh
npm install
npm test
npm run build
```
Commands above will generate the ready to use bundles under the `./dist` folder.

55 changes: 0 additions & 55 deletions angular2-pubsub.service.ts

This file was deleted.

7 changes: 4 additions & 3 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "angular2-pubsub",
"description": "Pub/Sub service for Angular 2",
"version": "1.1.1",
"main": "",
"version": "1.1.2",
"main": "./umd/angular2-pubsub.js",
"authors": [
"Semih KEŞKEK"
"Semih KEŞKEK",
"Mert SUSUR"
],
"license": "ISC",
"keywords": [
Expand Down
29 changes: 29 additions & 0 deletions karma-test-runner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

Error.stackTraceLimit = Infinity;

require('reflect-metadata');
require('zone.js/dist/zone');;
require('zone.js/dist/long-stack-trace-zone');
require('zone.js/dist/async-test');
require('zone.js/dist/fake-async-test');
require('zone.js/dist/sync-test');
require('zone.js/dist/proxy');
require('zone.js/dist/jasmine-patch');

var testing = require('@angular/core/testing');
var browser = require('@angular/platform-browser-dynamic/testing');

testing.TestBed.initTestEnvironment(
browser.BrowserDynamicTestingModule,
browser.platformBrowserDynamicTesting()
);

Object.assign(global, testing);

var testContext = require.context('./src', true, /\.spec\.ts/);

function requireAll(requireContext) {
return requireContext.keys().map(requireContext);
}

var modules = requireAll(testContext);
16 changes: 16 additions & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module.exports = function (config) {
config.set({
browsers: ['PhantomJS'],
frameworks: ['jasmine'],
reporters: ['mocha'],
singleRun: true,
preprocessors: { './karma-test-runner.js': ['webpack', 'sourcemap'] },
files: [
{ pattern: 'node_modules/babel-polyfill/browser.js', instrument: false },
{ pattern: './karma-test-runner.js', watched: false }
],
webpack: require('./webpack.config.test.js'),

webpackServer: { noInfo: true }
});
};
113 changes: 92 additions & 21 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,94 @@
{
"name": "angular2-pubsub",
"version": "1.1.1",
"description": "Pub/Sub service for Angular 2",
"repository": {
"type": "git",
"url": "git+https://github.com/sqlProvider/angular2-pubsub.git"
},
"keywords": [
"Angular2",
"pubsub",
"angular2-service"
],
"author": {
"name": "Semih KEŞKEK",
"email": "keskeksmh@gmail.com"
},
"license": "ISC",
"bugs": {
"url": "https://github.com/sqlProvider/angular2-pubsub/issues"
},
"homepage": "https://github.com/sqlProvider/angular2-pubsub#readme"
"name": "angular2-pubsub",
"version": "1.1.2",
"description": "Pub/Sub service for Angular 2",
"main": "./umd/angular2-pubsub.js",
"module": "./esm/src/index.js",
"typings": "./esm/src/index.d.ts",
"repository": {
"type": "git",
"url": "git+https://github.com/sqlProvider/angular2-pubsub.git"
},
"scripts": {
"test": "karma start",
"clean": "rm -rf dist",
"build-umd": "webpack --config webpack.config.umd.js",
"build-angular": "ngc -p tsconfig-ngc.json",
"copy-package-info": "cp ./package.json ./dist/package.json && cp ./bower.json ./dist/bower.json",
"build": "npm run clean && npm run build-umd && npm run build-angular && npm run copy-package-info"
},
"keywords": [
"Angular2",
"pubsub",
"angular2-service"
],
"author": {
"name": "Semih KEŞKEK",
"email": "keskeksmh@gmail.com"
},
"contributors": [
{
"name": "Mert Susur",
"email": "mail@mertsusur.com",
"url": "http://github.com/msusur"
}
],
"license": "ISC",
"bugs": {
"url": "https://github.com/sqlProvider/angular2-pubsub/issues"
},
"homepage": "https://github.com/sqlProvider/angular2-pubsub#readme",
"dependencies": {
"@angular/common": "^2.4.7",
"@angular/compiler": "^2.4.7",
"@angular/core": "^2.4.7",
"@angular/forms": "^2.4.7",
"@angular/platform-browser": "^2.4.7",
"jasmine-core": "^2.5.2",
"rxjs": "^5.1.0",
"ts-helpers": "^1.1.2",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/compiler-cli": "^2.4.7",
"@angular/platform-browser-dynamic": "^2.4.7",
"@types/es6-shim": "^0.31.32",
"@types/jasmine": "^2.5.41",
"@types/node": "^7.0.5",
"awesome-typescript-loader": "^3.0.4-rc.0",
"babel-polyfill": "^6.22.0",
"chai": "^3.5.0",
"codelyzer": "^2.0.0",
"commitizen": "^2.9.5",
"compression-webpack-plugin": "^0.3.2",
"extract-text-webpack-plugin": "^1.0.1",
"imports-loader": "^0.7.0",
"karma": "^1.4.1",
"karma-chrome-launcher": "^2.0.0",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.1.0",
"karma-mocha-reporter": "^2.2.2",
"karma-phantomjs-launcher": "^1.0.2",
"karma-remap-istanbul": "^0.4.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-typescript": "^2.1.6",
"karma-webpack": "^1.8.1",
"phantomjs-prebuilt": "^2.1.7",
"rxjs": "^5.0.1",
"sinon": "^1.17.4",
"sinon-chai": "^2.8.0",
"sourcemap-istanbul-instrumenter-loader": "^0.2.0",
"standard-version": "^4.0.0",
"stylelint-webpack-plugin": "^0.5.1",
"ts-loader": "^1.3.3",
"tslint": "^4.0.2",
"tslint-loader": "^3.3.0",
"typedoc": "^0.5.0",
"typescript": "^2.1.6",
"validate-commit-msg": "^2.8.0",
"webpack": "^1.13.0",
"webpack-dev-server": "^1.16.1",
"webpack-fix-default-import-plugin": "^1.0.1",
"zone.js": "^0.7.4"
}
}
49 changes: 49 additions & 0 deletions src/angular2-pubsub.service.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/* tslint:disable:no-unused-variable */

import { PubSubService } from './angular2-pubsub.service';
import { Observable, Subscriber } from 'rxjs';

describe('PubSubService', (): void => {
let pubService: PubSubService;

beforeEach(() => {
pubService = new PubSubService();
});

describe('$sub', (): void => {
it('should throw an error when event is falsy', (): void => {
expect(pubService.$sub.bind(undefined)).toThrow();
});

it('should return an observable when there is no callback', (): void => {
let result: any = pubService.$sub('test');
expect(result instanceof Observable).toBeTruthy();
});

it('should return a subscriber when there is a callback specified', (): void => {
let result: any = pubService.$sub('test', (v: any): void => {
'';
});
expect(result instanceof Subscriber).toBeTruthy();
});
});

describe('$pub', (): void => {
it('should throw an error when event is falsy', (): void => {
expect(pubService.$pub.bind(undefined)).toThrow();
});

it('should throw an error when event is not registered', (): void => {
expect(pubService.$pub.bind('not-registered')).toThrow();
});

it('should publish with parameters if the event is registered', (): void => {
let subscriberEventSpy: jasmine.Spy = jasmine.createSpy('subscriberEvent');
pubService.$sub('new-event', subscriberEventSpy);

pubService.$pub('new-event', 'foo');

expect(subscriberEventSpy).toHaveBeenCalledWith('foo');
});
});
});
Loading