chnl
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
; // create channelconst onData = ; // subscribe to channelonData;
bar.js
; // dispatch event to channelonData;
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 = ;const listener1 = console;const listener2 = { console; onData;};const listener3 = console;onData;onData; onData;// 1// 2onData;// 1// 2// 3
License
MIT @ Vitaliy Potapov