Security News
Input Validation Vulnerabilities Dominate MITRE's 2024 CWE Top 25 List
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
@flowio/events
Advanced tools
pub / sub event library for the browser. Provides a static reference to an event emitter so that the same channel can be used across files and other libraries.
Creates a reference to an event emitter by a channel. A channel is a key that refers to the an internal wolfy87-eventemitter
instance. Channels are referenced statically so multiple instances of ChannelEventEmitter will use the same EventEmitter instance internally. Triggers on channelEventEmitterA can be received by channelEventEmitterB when the same channel
value is used.
Parameter | Type | Default | Description |
---|---|---|---|
channel | string | default | The event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter. |
Parameter | Type | Default | Description |
---|---|---|---|
emitter | Object | Internal wolfy87-eventemitter EventEmitter instance | |
channel | string | default | The event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter. |
on(event, callback)
Subscribe to an event and execute the callback when it is triggered.
const events = new ChannelEventEmitter();
events.on('myEvent', (data) => console.log('My event data!', data));
once(event, callback)
Subscribe to an event and execute the callback once and then remove it.
const events = new ChannelEventEmitter();
events.once('myEvent', (data) => console.log('My event data!', data));
trigger('myEvent', 'Hello!');
// -> My event data! Hello!
trigger('myEvent', 'Hello!');
// Nothing logged.
off(event, callback)
Remove a callback subscription to an event.
const events = new ChannelEventEmitter();
const myCallback = (data) => console.log('My event data!', data);
events.on('myEvent', myCallback);
trigger('myEvent', 'Hello!');
// -> My event data! Hello!
off('myEvent', myCallback);
trigger('myEvent', 'Hello!');
// Nothing logged.
trigger(event, data)
Trigger an event and pass the provided data to the callback of any subscribers.
const events = new ChannelEventEmitter();
events.on('myEvent', (data) => console.log('My event data!', data));
trigger('myEvent', 'Hello!');
// -> My event data! Hello!
removeAll()
Remove all subscriptions across all events
Creates an event emitter that will automatically execute callbacks if an event has been triggered already.
Parameter | Type | Default | Description |
---|---|---|---|
channel | string | default | The event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter. |
triggerOnceEvents | array(String) | [] | Events that can only be triggered once and will automatically execute callbacks of any future subscriptions |
Property | Type | Default | Description |
---|---|---|---|
emitter | string | default | Internal ChannelEventEmitter instance. |
triggerOnceEvents | array(String) | [] | Events that can only be triggered once and will automatically execute callbacks of any future subscriptions |
previouslyTriggered | array(Object) | [] | Events that have already been triggered on this instance of TriggerOnceEvents. Each entry is an object with the shape { key, data } |
on(event, callback)
Subscribe to an event.
const events = new ChannelEventEmitter();
events.on('myEvent', (data) => console.log('Data from my event!', data));
trigger(event, data)
Trigger an event.
const events = new ChannelEventEmitter();
events.trigger('myEvent', 'Hello World');
getPreviouslyTriggeredEvent(event)
Get previously triggered event
const events = new ChannelEventEmitter();
events.trigger('myEvent', 'Hello World');
console.log(events.getPreviouslyTriggeredEvent('myEvent');
// -> { key: 'myEvent', data: 'Hello World' }
resetPreviouslyTriggered()
Reset list of previously triggered events
const events = new ChannelEventEmitter();
events.trigger('myEvent', 'Hello World');
console.log(events.getPreviouslyTriggeredEvent('myEvent');
// -> { key: 'myEvent', data: 'Hello World' }
events.resetPreviouslyTriggered();
console.log(events.previouslyTriggered);
// -> []
FAQs
Event Bus (Pub/Sub)
The npm package @flowio/events receives a total of 0 weekly downloads. As such, @flowio/events popularity was classified as not popular.
We found that @flowio/events demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 10 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.