JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 42
  • Score
    100M100P100Q54824F
  • License ISC

Events is a publish-subscribe style event system based on sqlProvider/angular2-pubsub

Package Exports

  • angular4-events

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (angular4-events) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Events Service for Angular

Events is a publish-subscribe style event system based on sqlProvider/angular2-pubsub and modified to be similar to ionic-angular/Events.

Usage

  • Import service in your codes or download via npm.

    • Angular 4: npm install --save angular4-events@4.0.1
    • Angular 5: npm install --save angular4-events@5.0.0
    • Angular 6: npm install --save angular4-events@5.0.2
    • Angular 8: npm install --save angular4-events@8.0.0
    • Angular 10: npm install --save angular4-events@10.0.1
    • Angular 11: npm install --save angular4-events@11.0.1
    • ⚠️ Version 5.0.1 is incompatible with Angular 5 and should have been version 6.0.0.
  • Add module bundle to imports in your application.

...

import { EventsModule } from 'angular4-events';

@NgModule({
    declarations: [
        ...
    ],
    imports: [
        ...
        EventsModule.forRoot()
    ]
})

...
  • And import service wherever you want

Documentation

Class Overview

declare class EventsService {
    private events: Object;
    publish(event: string, eventObject?: any): void;
    subscribe(): undefined;
    subscribe(event: string): Observable<any>;
    subscribe(event: string, callback: (value: any) => void): Subscription;
    subscribe(event: string, callback: (value: any) => void, error: (error: any) => void): Subscription;
    subscribe(event: string, callback: (value: any) => void, error: (error: any) => void, complete: () => void): Subscription;
}

EventsService.publish(event: string, eventObject?: any): void

Publish event to all subscriber.

etc.

export class OverlayComponent implements OnInit, OnDestroy {
    constructor(private events: EventsService) { }

    anyFunc(){
        this.events.publish('pleaseCloseSidenav', 'helloIAmOverlay');
    }
}

EventsService.subscribe(event: string): Observable

Subscribe to channel.

etc.

export class NavigationComponent implements OnInit, OnDestroy {
    sideanvSub: any;
    
    constructor(private pubsub: EventsService) { }

    ngOnInit() {
        // usage of subscribe(event: string): <Observable<any>>;
        this.closeSidenavSub = this.pubsub.subscribe('pleaseCloseSidenav').subscribe((from) => {
            this.sidenavOpened = false;
        });

        // usage of subscribe(event: string, callback: (value: any) => void, error?: (error: any) => void, complete?: () => void): Subscription;
        this.openSidenavSub = this.pubsub.subscribe('pleaseOpenSidenav', (from) => {
            this.sidenavOpened = true;
        });
    }
    ngOnDestroy() {
        this.closeSidenavSub.unsubscribe();
        this.openSidenavSub.unsubscribe();
    }

Build the source

Follow the steps to run the tests and build the source code.

npm install
npm test
npm run build

Commands above will generate the ready to use bundles under the ./dist folder.