simple cross-platform event emitter based on EventEmitter
const energy = require("energy")
const emitter = energy()
Or use new
if you prefer. Either way works :)
const energy = require("energy")
const emitter = new energy
- emitter.on(event, listener)
- emitter.off(event?, listener?, quota?)
- emitter.emit(event, ...args)
- emitter.once(event, listener)
- emitter.clone()
- emitter.listeners(event)
- emitter.init()
- emitter.to(target)
- energy.to(target)
- emitter refers to an
energy()
object - event refers to an event name
- listener refers to a function that listens to an event
- Add listener for event
- @return emitter
- Remove listener(s)
.off()
removes all listeners for all events.off(event)
removes all event listeners.off(event, listener)
removes all occurrences of event listener.off(event, listener, quota)
remove quota occurrences of event listener
- @return emitter
- Fire event listeners (in sequence) with the supplied arguments
- Listeners run in the context of emitter
- @return number of invoked listeners
- Add a one-time event listener
- @return emitter
- Clone an emitter at its current state
- @return a new emitter
- Access the listeners array for the specified event
- @return array (reference)
- Reinitialize an emitter
- @return emitter
- Make target emitter-like based on
emitter
as the source. - @return emitter
- Make target emitter-like based on a
energy()
object as the source - @return target with emitter methods and properties
Works in node and in any browser. Tested in node, Chrome, FF, Opera, IE8