1.2.0 • Published 6 years ago
chnl v1.2.0
chnl
Implementation of event channels (pub/sub, dispatcher, emitter) inspired and compatible with Chrome extensions events API.
Install
npm i chnl --saveDocs
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
// 3License
MIT @ Vitaliy Potapov
1.2.0
6 years ago
1.1.1
6 years ago
1.1.0
6 years ago
1.0.0
6 years ago
0.6.1
6 years ago
0.6.0
6 years ago
0.5.0
7 years ago
0.4.2
7 years ago
0.4.1
7 years ago
0.4.0
9 years ago
0.3.0
9 years ago
0.2.5
9 years ago
0.2.4
9 years ago
0.2.3
9 years ago
0.2.2
9 years ago
0.2.1
9 years ago
0.2.0
9 years ago
0.1.14
10 years ago
0.1.13
10 years ago
0.1.12
10 years ago
0.1.11
10 years ago
0.1.10
10 years ago
0.1.9
10 years ago
0.1.8
10 years ago
0.1.7
10 years ago
0.1.6
10 years ago
0.1.5
10 years ago
0.1.4
10 years ago
0.1.3
10 years ago
0.1.2
10 years ago
0.1.1
10 years ago
0.1.0
10 years ago