[go: up one dir, main page]

@vates/event-listeners-manager

1.0.1 • Public • Published

@vates/event-listeners-manager

Package Version License PackagePhobia Node compatibility

Install

Installation of the npm package:

> npm install --save @vates/event-listeners-manager

Usage

This library is compatible with Node's EventEmitter and web browsers' EventTarget APIs.

API

import { EventListenersManager } from '@vates/event-listeners-manager'

const events = new EventListenersManager(emitter)

// adding listeners
events.add('foo', onFoo).add('bar', onBar).on('baz', onBaz)

// removing a specific listener
events.remove('foo', onFoo)

// removing all listeners for a specific event
events.removeAll('foo')

// removing all listeners
events.removeAll()

Typical use case

Removing all listeners when no longer necessary.

Manually:

const onFoo = () => {}
const onBar = () => {}
const onBaz = () => {}
emitter.on('foo', onFoo).on('bar', onBar).on('baz', onBaz)

// CODE LOGIC

emitter.off('foo', onFoo).off('bar', onBar).off('baz', onBaz)

With this library:

const events = new EventListenersManager(emitter)

events.add('foo', () => {})).add('bar', () => {})).add('baz', () => {}))

// CODE LOGIC

events.removeAll()

Contributions

Contributions are very welcomed, either on the documentation or on the code.

You may:

  • report any issue you've encountered;
  • fork and create a pull request.

License

ISC © Vates SAS

Package Sidebar

Install

npm i @vates/event-listeners-manager

Weekly Downloads

14

Version

1.0.1

License

ISC

Unpacked Size

4.56 kB

Total Files

3

Last publish

Collaborators

  • stephane-m-dev
  • florent.beauchamp
  • mathieura
  • julien-f
  • marsaud
  • olivierlambert
  • pdonias
  • tgoettelmann
  • enishowk
  • b-nollet
  • mlssfrncjrg
  • arnogues
  • joris-k