super-events

1.1.0 • Public • Published

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 listener
  • listenOnce : create once listener for event and returns listener
  • listenFirst : create and prepend listener for event and returns listener
  • listenFirstOnce 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

Dependents (0)

Package Sidebar

Install

npm i super-events

Weekly Downloads

0

Version

1.1.0

License

ISC

Unpacked Size

27.1 kB

Total Files

25

Last publish

Collaborators

  • teajo