Tiny event emitter/event listener for nodejs and browsers.
npm install --save smart-table-events
yarn add smart-table-events
import {emitter} from 'smart-table-events';
const em = emitter();
//a listener function
const listener = (...args) => console.log(args);
//register to an event
em.on('MY_EVENT',listener);
//dispatch event
em.dispatch('MY_EVENT','foo','bar');
// > ['foo','bar']
//unsubscribe
em.off()// all listeners of all events;
em.off('MY_EVENT')// all listeners of event "MY_EVENT")
em.off('MY_EVENT', listener)// remove a particular listener
Create convenient/meaningful methods to register events.
import {emitter, proxyListener} from 'smart-table-events';
const em = emitter();
const proxyFactory = proxyListener({MY_EVENT:'myMethod'});
const instance = proxyFactory({emitter:em);
const listener = (...args) => console.log(args);
//register with convenient method
instance.myMethod(listener);
em.dispatch('MY_EVENT','foo','bar');
// > ['foo','bar']
//unsubscribe
instance.off('MY_EVENT') //unregister all listeners to MY_EVENT held by the proxy instance
instance.off() //unregister all listeners held by the proxy instance
npm test
yarn test
Bugs only please (or feature request to be discussed), must come with running example