Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@flowio/events

Package Overview
Dependencies
Maintainers
10
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@flowio/events

Event Bus (Pub/Sub)

  • 0.1.18
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
21
increased by2000%
Maintainers
10
Weekly downloads
 
Created
Source

@flowio/events

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.

API

ChannelEventEmitter

TriggerOnceEvents

ChannelEventEmitter(channel)

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.

Parameters

ParameterTypeDefaultDescription
channelstringdefaultThe event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter.

Properties

ParameterTypeDefaultDescription
emitterObjectInternal wolfy87-eventemitter EventEmitter instance
channelstringdefaultThe event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter.

Methods

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

TriggerOnceEvents({ channel = 'default', triggerOnceEvents = [] } = {})

Creates an event emitter that will automatically execute callbacks if an event has been triggered already.

Parameters

ParameterTypeDefaultDescription
channelstringdefaultThe event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter.
triggerOnceEventsarray(String)[]Events that can only be triggered once and will automatically execute callbacks of any future subscriptions

Properties

PropertyTypeDefaultDescription
emitterstringdefaultInternal ChannelEventEmitter instance.
triggerOnceEventsarray(String)[]Events that can only be triggered once and will automatically execute callbacks of any future subscriptions
previouslyTriggeredarray(Object)[]Events that have already been triggered on this instance of TriggerOnceEvents. Each entry is an object with the shape { key, data }

Methods

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

Package last updated on 21 Feb 2022

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc