Package Exports
- microdispatch
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 (microdispatch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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'});