@costadvl/school-bus
v0.0.3
Published
school-bus is a prototype of an event bus based on the observer and subscriber pattern
Downloads
1
Readme
School Bus
import { BusEmitter } from './emitter';
import { BusObserver } from './observer';
import { Static } from './static';
class Receiver extends BusObserver {
constructor(id: string) {
super(id);
}
notification(event: string, emitter: string, content: any) {
console.log(...arguments);
}
}
const mother = new Receiver('motherShip').observeEvent(['secret', 'mother']);
const planet = new Receiver('planet').observeEvent(['secret']);
const ship = new BusEmitter('ship');
Static.DefaultBus.registerObserver([mother, planet]);
ship.send('secret', { star: 'delilah', status: 'save' });
ship.send('mother', { star: 'delilah', status: 'save' });