1.0.0 • Published 3 years ago

@tawaship/transceiver v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

@tawaship/transceiver

A module for mutual messaging between multiple objects.

Build Status MIT License


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)