Fake .catch() method of Promise
Callback function which will be triggered after .reject()
Emit an event to listeners
Event name
Parameters that we need to emit to listeners
Get all event names
Array of event names
Add new event listener
Event name
Callback that will be triggered if event emitted
Add event listener for one time event
Event name
Callback that will be triggered if event emitted
Fake .reject() method of Promise
Error to return in .catch()
Remove listeners for a given eventName
otherwise all listeners
Name of event
Fake .resolve() method of Promise
Value to return in .then()
Fake .then() method of Promise
Callback function which will be triggered after .resolve()
Generated using TypeDoc
Introduction
EventDispatcher is an alternative solution to
EventEmitter
that allowed you to delivery event and manage listeners easier. It's working on both Node.js and browser.Guide of EventDispatcher
You could use EventDispatcher to transmit event between object or from internal to outside world.
import { EventDispatcher } from 'noqueue'; // Create new instance of EventDispatcher const iEventDispatcher = new EventDispatcher(); // Add new event listener iEventDispatcher.on('new-message', (message: string) => { console.log('Received message:', message); }); // Add one time event listener iEventDispatcher.once('new-message', (message: string) => { console.log("We're only receive this one time:", message); }); // Emit event to listener iEventDispatcher.emit('new-message', "Hi! I'm EventDispatcher."); iEventDispatcher.emit('new-message', 'You did it well');
Or extend your class:
export YourNewClass extends EventDispatcher { // Your code here, you're almost access all methods // of EventDispatch except the private one }