evento is just another simple event bus library written in TypeScript
run
yarn add evento-ts
Oh but I don't like yarn
npm install evento-ts
How do I use it ?
const Evento = require('evento-ts');
const EventBus = new Evento();
EventBus.on('stuff', (payload: any) => {
console.log(payload);
});
EventBus.once('stuff', (payload: any) => {
console.log(payload);
});
// Somewhere in your code
EventBus.off('stuff', callback);
// Somewhere in your code
EventBus.dispatch('stuff', 'take this!');
const unsubscribe = EventBus.on('stuff', (payload: any) => {
console.log(payload);
});
unsubscribe();