super-events
v1.1.0
Published
events module which add features to nodejs events core module
Downloads
3
Readme
SuperEvents
SuperEvents is a lib which extends native Nodejs events API, so you can use native EventEmitter methods and also enhanced methods as :
listen
: create listener for event and returns listenerlistenOnce
: create once listener for event and returns listenerlistenFirst
: create and prepend listener for event and returns listenerlistenFirstOnce
create and prepend once listener for event and returns listener
Listener returned has following methods :
remove
disable
enable
enabled
In event handler, the first argument is the signal event with stopPropagation
method.
Features
- Allows to stop event signal propagation
- Allows to remove, enable, disable a listener
Examples
Simple emit/on
const { SuperEvents } = require('super-events')
const se = new SuperEvents()
const listener = se.listen('test', (signal, arg1, arg2) => console.log(arg1 + arg2))
se.emit('test', 1, 2)
Remove listener
const { SuperEvents } = require('super-events')
const se = new SuperEvents()
const listener = se.listen('test', (signal, arg1, arg2) => console.log(arg1 + arg2))
listener.remove()
se.emit('test', 1, 2)
Disable listener
const { SuperEvents } = require('super-events')
const se = new SuperEvents()
const listener = se.listen('test', (signal, arg1, arg2) => console.log(arg1 + arg2))
listener.disable()
se.emit('test', 1, 2)
Installation
No runtime dependencies Using typescript + mocha as dev dependencies
Build
npm run build
Test
npm run test