- new Evemit()
- evemit.on(event, fn, [context])
- evemit.once(event, fn, [context])
- evemit.emit(event, [...arg])
- evemit.off(event, fn)
- evemit.listeners([event])
Evemit constructor.
Register a new event listener for a given event.
Params
- event
string
- Event name. - fn
function
- Callback function (listener). - [context]
*
- Context for function execution.
Returns: Evemit - Current instance.
Add an event listener that's only called once.
Params
- event
string
- Event name. - fn
function
- Callback function (listener). - [context]
*
- Context for function execution.
Returns: Evemit - Current instance.
Emit an event to all registered event listeners.
Params
- event
string
- Event name. - [...arg]
*
- One or more arguments to pass to the listeners.
Returns: bool
- Indication, true
if at least one listener was executed,
otherwise returns false
.
Remove event listeners.
Params
- event
string
- The event to remove. - fn
function
- The listener that we need to find.
Returns: Evemit - Current instance.
Get a list of assigned event listeners.
Params
- [event]
string
- The events that should be listed. If not provided, all listeners are returned. Use the propertyEvemit.events
if you want to get an object like
{event1: [array of listeners], event2: [array of listeners], ...}
Returns: array
Minimal and fast JavaScript event emitter for Node.js and front-end.
Author: Nicolas Tallefourtane [email protected]
License: MIT https://github.com/Nicolab/evemit/blob/master/LICENSE