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

channel-emitter

v0.1.0

Published

An event emitter with channel and broadcast support

Downloads

4

Readme

channel-emitter

Codeship Status for CentralPing/channel-emitter Build Status Code Climate for CentralPing/channel-emitter Dependency Status for CentralPing/channel-emitter

Installation

npm i --save channel-emitter

What is ChannelEmitter?

  • A "singleton" EventEmitter - at its core it is a pseudo-singleton (it relies on the node module cache) EventEmitter. Every module within a process that requires ChannelEmitter will recieve the same cached object.
  • A multi-channel emitter - ChannelEmitter supports channels as well as sub-channels. This allows listeners for an event on specific channels as well as emitting up to parent channels and broadcasting down to sub-channels.

Features

  • Provides a "singleton" (a node module cached object).
  • Allows name-spacing of events through "channels".
  • Every channel can have multiple sub-channels.
  • A channel can emit to all events on the channel as well as up to all parent channels.
  • A channel can broadcast to all events on the channel as well as down to all sub-channels.

Examples

Basic Usage

As a singleton

/* a.js */
var channelEmitter = require('channel-emitter');
channelEmitter.on('foo', function () { console.log(arguments); });

/* b.js */
var channelEmitter = require('channel-emitter');
channelEmitter.emit('foo', true, {foo: []}, 123);

/* c.js */
require('./a');
require('./b');
// outputs: { '0': true, '1': { foo: [] }, '2': 123 }

With channels

/* a.js */
var channelEmitter = require('channel-emitter');
channelEmitter.on('foobar', function () { console.log('foobar: ', arguments); });
channelEmitter.on('foo.bar', function () { console.log('foo.bar: ', arguments); });

channelEmitter.emit('foobar', 'hi');
// returns true;
// outputs: foobar: { 0: 'hi' }

channelEmitter.emit('bar', 'hello');
// returns false;
// outputs:

channelEmitter.emit('foo.foobar', 'hi');
// returns true;
// outputs: foobar: { 0: 'hi' }

channelEmitter.emit('foo.bar', 'hello');
// returns true;
// outputs: foo.bar: { 0: 'hello' }

channelEmitter.broadcast('foobar', 'hi');
// returns true;
// outputs: foobar: { 0: 'hi' }

channelEmitter.broadcast('bar', 'hello');
// returns true;
// outputs: foo.bar: { 0: 'hello' }

channelEmitter.broadcast('foo.foobar', 'hi');
// returns false;
// outputs:

channelEmitter.broadcast('foo.bar', 'hello');
// returns true;
// outputs: foo.bar: { 0: 'hello' }

API Reference

Example

var channel_emitter = require('channel-emitter');

channel-emitter~addListener(eventName, listener) ⇒ ChannelEmitter

Wrapper for the EventEmitter.addListener method that will auto-add channels if the specified delimiter is used in the name.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the event | | listener | function | the listener for the event |

channel-emitter~removeListener(eventName, listener) ⇒ ChannelEmitter

Wrapper for the EventEmitter.removeListener method that will remove events from a specified channl if the specified delimiter is used in the name.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the event | | listener | function | the listener for the event |

channel-emitter~removeAllListeners([eventName]) ⇒ ChannelEmitter

Wrapper for the EventEmitter.removeAllListeners method that will remove if the specified delimiter is used in the name.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | [eventName] | string | the name for the event |

channel-emitter~listenerCount(eventName) ⇒ ChannelEmitter

Wrapper for the EventEmitter.listenerCount method that will return the listener count on a channel (including name-spaced events).

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the event |

channel-emitter~listeners(eventName) ⇒ ChannelEmitter

Wrapper for the EventEmitter.listeners method that will return the listeners on a channel (including name-spaced events).

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the event |

channel-emitter~on(eventName, listener) ⇒ ChannelEmitter

Wrapper for the EventEmitter.on method that will auto-add channels if the specified delimiter is used in the name.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the event | | listener | function | the listener for the event |

channel-emitter~addChannel(channelName) ⇒ ChannelEmitter

Adds a sub-channel to the current channel.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | channelName | string | the name for the channel |

channel-emitter~removeChannel(channelName) ⇒ ChannelEmitter

Removes the sub-channel from the current channel.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | channelName | string | the name for the channel |

channel-emitter~emit(eventName, [...args]) ⇒ Boolean

EventEmitter wrapper that emits an event to siblings and direct ancestor channels.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the registered event | | [...args] | * | arguments to emit to the event |

channel-emitter~broadcast(eventName, [...args]) ⇒ Boolean

Broadcasts an event to siblings and descendent channels.

Kind: inner method of channel-emitter

| Param | Type | Description | | --- | --- | --- | | eventName | string | the name for the registered event | | [...args] | * | arguments to broadcast to the event |

License

Apache 2.0