Ontime EventEmitter
The class is used to implement pattern Mediator. The common idea of the class has been taken from NodeJS native class EventEmitter and class BackboneJS Events.
How to install
npm install ontime-eventemitter
How to use
; ; // create callback function; // subscribe callbackemitter.on'say', cb; // send eventemitter.emit'say', 'John'; // -> Hello Johnemitter.emit'say', 'Helen'; // -> Hello Helen // unsubscribe callbackemitter.off'say', cb;
Methods
on
on(name: name, callback: Function) - Subscribe callback. The callback will be invoked whenever the event is fired.
once
once(name: name, callback: Function) - Just like "on", but causes the callback to fire only once before being removed.
off
off(name: name, callback: Function) - Unsubscribe previously callback.
emit
emit(name: name, [...args]) - Emit callbacks for the given event. Subsequent arguments to trigger will be passed along to the event callbacks.
stopListening
stopListening() - Remove all listeners.