@tawaship/transceiver

A module for mutual messaging between multiple objects.

Usage no npm install needed!

<script type="module">
  import tawashipTransceiver from 'https://cdn.skypack.dev/@tawaship/transceiver';
</script>

README

@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)