t-event-dispatcher
TypeScript icon, indicating that this package has built-in type declarations

0.0.3 • Public • Published

T-Event-Dispatcher

Allows to register subscribers and dispatch events across the application.

Usage

Simply create a class and put annotations on its methods:

import {EventSubscriber, On} from "t-event-dispatcher/Annotations";
 
@EventSubscriber()
export class UserEventSubscriber {
 
    @On('onUserCreate')
    onUserCreate(user: User) {
        console.log('User ' + user.name + ' created!');
    }
 
    @On('onStatusUpdate')
    updateUserStatus(status: string) {
        console.log('New status: ' + status);
    }
 
}

Then use EventDispatcher class to dispatch events:

import {EventDispatcher} from "t-event-dispatcher/EventDispatcher";
 
require('./subscriber/UserEventSubscriber');
// you can also require the whole directory using: Utils.requireAll([__dirname + '/subscriber']);
 
let eventDispatcher = new EventDispatcher();
 
eventDispatcher.dispatch('onUserCreate', new User('Johny'));
eventDispatcher.dispatch('onStatusUpdate', 'hello world');
 

Take a look on samples in ./sample for more examples of usages.

Todos

  • cover with tests
  • more documentation

Readme

Keywords

none

Package Sidebar

Install

npm i t-event-dispatcher

Weekly Downloads

0

Version

0.0.3

License

Apache-2.0

Last publish

Collaborators

  • pleerock