npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@flowio/events

v0.1.18

Published

Event Bus (Pub/Sub)

Downloads

97

Readme

@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

Parameter | Type | Default | Description --------- | ------ | ------- | ------------------ channel | string | default | The event emitter channel to use. Can be reused across multiple instances of ChannelEventEmitter.

Properties

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.

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

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

Properties

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 }

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);
// -> []