🚌 This is a minimalist event hub.
npm i @resreq/event-hub
or
yarn add @resreq/event-hub
If you use the Deno
Please add to import_map.json
.
import EventHub from 'https://esm.sh/@resreq/event-hub'
import EventHub from '@resreq/event-hub'
const hub = new EventHub()
hub.on('custom-send', (message) => {
console.log(message) // => Hello, EventHub!
})
hub.emit('custom-send', 'Hello, EventHub!')
Event
Event name type.
type Event = string | symbol
- Arguments:
{Event | Event[]} event
{Function} handler
-
Usage:
Listen for a custom event on the current Instance. Events can be triggered by
instance.emit
. The handler will receive all the additional arguments passed into these event-triggering methods.
- Arguments:
{Event} event
{Function} handler
-
Usage:
Listen for a custom event, but only once. The listener will be removed once it triggers for the first time.
- Arguments:
{Event | Event[]} event
{Function} [handler]
-
Usage:
Remove custom event listener(s).
- If no arguments are provided, remove all event listeners;
- If only the event is provided, remove all listeners for that event;
- If both event and handler are given, remove the listener for that specific handler only.
-
Arguments:
-
{Event} event
-
{any} ...args
-
-
Usage:
Trigger an event on the current instance. Any additional arguments will be passed into the listener’s handler function.
This project is licensed under the MIT License - see the LICENSE file for details