Nodeschool Public Materials
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

microdispatch

1.2.0 • Public • Published

Build Status

MicroDispatcher

minimal and performant event dispatcher / emitter supporting custom event objects

Usage

create instance

import MicroDispatch from 'microdispatch';
 
const micro = new MicroDispatch();
 
micro.on('test', (e)=>{
  console.log(e.type === 'test');
  console.log(e.foo === 'bar');
});
 
micro.dispatch('test', {foo:'bar'});
 

use global instance

import {dispatcher} from 'microdispatch';
 
dispatcher.on('test', (e)=>{
  console.log(e.type === 'test');
  console.log(e.foo === 'bar');
});
 
dispatcher.emit('test', {foo:'bar'});
 

use decorator

import {microdispatch} from 'microdispatch';
 
//v1: use es7 decorators
@microdispatch
class Tester {
    onTest(e){
        console.log(e.type === 'test');
        console.log(e.foo === 'bar');
    }
}
 
//v2 use the decorator as a function
microdispatch(Tester);
 
const tt = new Tester();
 
tt.on('test', tt.onTest);
tt.dispatch('test', {foo:'bar'});

install

npm i microdispatch

Downloadsweekly downloads

6

version

1.2.0

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability