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

chnl

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chnl

Implementation of event channels compatible with Chrome extensions events API

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

chnl

Build Status npm version license

Implementation of event channels (pub/sub, dispatcher, emitter) inspired and compatible with Chrome extensions events API.

Install

npm i chnl --save

Docs

https://vitalets.github.io/chnl

Usage

foo.js

import Channel from 'chnl';

// create channel
export const onData = new Channel();

// subscribe to channel
onData.addListener(data => console.log(data));

bar.js

import {onData} from './foo';

// dispatch event to channel
onData.dispatch({foo: 'bar'});

Adding/removing listeners in dispatching loop

Chnl makes a copy of the listeners before starting dispatching loop. So modifying listeners list (adding/removing) in dispatching loop will affect only the next dispatch:

const onData = new Channel();
const listener1 = () => console.log(1);
const listener2 = () => {
  console.log(2);
  onData.addListener(listener3);
};
const listener3 = () => console.log(3);
onData.addListener(listener1);
onData.addListener(listener2);

onData.dispatch();
// 1
// 2
onData.dispatch();
// 1
// 2
// 3

License

MIT @ Vitaliy Potapov

FAQs

Package last updated on 06 May 2020

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