0.1.1 • Published 5 years ago

@beancommons/emitter v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

@beancommons/emitter

Wrap EventEmitter3 and return a single case.

Install

npm install --save @beancommons/emitter

Usage

import emitter from '@beancommons/emitter';

function loading(data) {
    console.log(data);
}
emitter.on('loading', loading);
emitter.trigger('loading', {data: 'data'});
emitter.off('loading', loading);
emitter.once('loading', loading);

API

// Adds the listener function to the end of the listeners array for the event named eventName. 
addListener(eventName, listener)
// Alias for addListener
on(eventName, listener) 
// Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.
once(eventName, listener) 
// Removes the specified listener from the listener array for the event named eventName.
removeListener(eventName, listener) 
// Alias for removeListener
off(eventName, listener) 
// Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.
emit(eventName, data) 
// Alias for emit
trigger(eventName, data) 
// Removes all listeners, or those of the specified eventName.
removeAllListeners(eventName) 
// Alias for removeAllListeners
clear(eventName)
// set MaxListeners, default is Infinity
setMaxListeners(number)