eventemitter3
- Version 5.0.1
- Published
- 73.4 kB
- No dependencies
- MIT license
Install
npm i eventemitter3
yarn add eventemitter3
pnpm add eventemitter3
Overview
EventEmitter3 focuses on performance while maintaining a Node.js AND browser compatible interface.
Index
Classes
class EventEmitter
class EventEmitter< EventTypes extends EventEmitter.ValidEventTypes = string | symbol, Context extends any = any> {}
Minimal
EventEmitter
interface that is molded against the Node.jsEventEmitter
interface.
property prefixed
static prefixed: string | boolean;
method addListener
addListener: <T extends EventEmitter.EventNames<EventTypes>>( event: T, fn: EventEmitter.EventListener<EventTypes, T>, context?: Context) => this;
method emit
emit: <T extends EventEmitter.EventNames<EventTypes>>( event: T, ...args: EventEmitter.EventArgs<EventTypes, T>) => boolean;
Calls each of the listeners registered for a given event.
method eventNames
eventNames: () => Array<EventEmitter.EventNames<EventTypes>>;
Return an array listing the events for which the emitter has registered listeners.
method listenerCount
listenerCount: (event: EventEmitter.EventNames<EventTypes>) => number;
Return the number of listeners listening to a given event.
method listeners
listeners: <T extends EventEmitter.EventNames<EventTypes>>( event: T) => Array<EventEmitter.EventListener<EventTypes, T>>;
Return the listeners registered for a given event.
method off
off: <T extends EventEmitter.EventNames<EventTypes>>( event: T, fn?: EventEmitter.EventListener<EventTypes, T>, context?: Context, once?: boolean) => this;
method on
on: <T extends EventEmitter.EventNames<EventTypes>>( event: T, fn: EventEmitter.EventListener<EventTypes, T>, context?: Context) => this;
Add a listener for a given event.
method once
once: <T extends EventEmitter.EventNames<EventTypes>>( event: T, fn: EventEmitter.EventListener<EventTypes, T>, context?: Context) => this;
Add a one-time listener for a given event.
method removeAllListeners
removeAllListeners: (event?: EventEmitter.EventNames<EventTypes>) => this;
Remove all listeners, or those of the specified event.
method removeListener
removeListener: <T extends EventEmitter.EventNames<EventTypes>>( event: T, fn?: EventEmitter.EventListener<EventTypes, T>, context?: Context, once?: boolean) => this;
Remove the listeners of a given event.
Namespaces
namespace EventEmitter
namespace EventEmitter {}
variable EventEmitter
const EventEmitter: EventEmitterStatic;
interface EventEmitterStatic
interface EventEmitterStatic {}
construct signature
new < EventTypes extends ValidEventTypes = string | symbol, Context = any>(): EventEmitter<EventTypes, Context>;
interface ListenerFn
interface ListenerFn<Args extends any[] = any[]> {}
call signature
(...args: Args): void;
type ArgumentMap
type ArgumentMap<T extends object> = { [K in keyof T]: T[K] extends (...args: any[]) => void ? Parameters<T[K]> : T[K] extends any[] ? T[K] : any[];};
type EventArgs
type EventArgs<T extends ValidEventTypes, K extends EventNames<T>> = Parameters< EventListener<T, K>>;
type EventListener
type EventListener<T extends ValidEventTypes, K extends EventNames<T>> = T extends | string | symbol ? (...args: any[]) => void : ( ...args: ArgumentMap<Exclude<T, string | symbol>>[Extract<K, keyof T>] ) => void;
type EventNames
type EventNames<T extends ValidEventTypes> = T extends string | symbol ? T : keyof T;
type ValidEventTypes
type ValidEventTypes = string | symbol | object;
object
should be in either of the following forms:interface EventTypes {'event-with-parameters': any[]'event-with-example-handler': (...args: any[]) => void}
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (10)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/eventemitter3
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/eventemitter3)
- HTML<a href="https://www.jsdocs.io/package/eventemitter3"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 4034 ms. - Missing or incorrect documentation? Open an issue for this package.