@tawaship/transceiver
A module for mutual messaging between multiple objects.
Setup
NPM
npm install --save @tawaship/transceiver
import { Transceiver } from '@tawaship/transceiver';
Browser
git clone https://github.com/tawaship/Transceiver
<script src="/path/to/dist/Transceiver.min.js"></script>
Usage
Create transceivers
const [ A, B, C ] = Transceiver.create(3);
Listen event
A.on('hoge', e => {
console.log('A');
});
B.on('moge', e => {
console.log('B');
});
C.on('fuga', e => {
console.log('C');
});
Send event
Note that unlike a typical Emitter, it does not fire an event to itself.
A.emit('hoge'); // (nothing)
A.emit('moge'); // B
A.emit('fuga'); // C
B.emit('hoge'); // A
B.emit('moge'); // (nothing)
B.emit('fuga'); // C
C.emit('hoge'); // A
C.emit('moge'); // B
C.emit('fuga'); // (nothing)