1.2.5 • Published 10 months ago

@zero-dependency/emitter v1.2.5

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

@zero-dependency/emitter

npm version npm bundle size (scoped) npm license

Installation

npm install @zero-dependency/emitter
yarn add @zero-dependency/emitter
pnpm add @zero-dependency/emitter

Usage

import { Emitter } from '@zero-dependency/emitter'

type Events = {
  message: (msg: string) => void
}

const events = new Emitter<Events>()

function onMessage(msg: string): void {}

// Adds the listener function for the event named message.
events.on('message', onMessage)

// Adds a one-time listener function for the event named message.
// The next time message is triggered, this listener is removed and then invoked.
events.once('message', onMessage)

// Synchronously calls each of the listeners registered for the event named message,
// in the order they were registered, passing the supplied arguments to each.
// Returns true if the event had listeners, false otherwise.
events.emit('message', 'hello world')

// Removes the specified listener from the listener array for the event named message.
events.off('message', onMessage)

// Removes all listeners, or those of the specified message.
events.removeAllListeners('message')

// Removes all listeners for events.
events.removeAllListeners()

// Returns an array listing the events for which the emitter has registered listeners.
// The values in the array are strings or Symbols.
events.eventNames()

// Returns an array of listeners for an event named message.
events.listeners('message')

// Returns the number of listeners listening to the event named message.
events.listenerCount('message')
1.2.5

10 months ago

1.2.4

10 months ago

1.2.3

10 months ago

1.2.2

11 months ago

1.2.0

1 year ago

1.2.1

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.2

1 year ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.0

2 years ago