alejandrolechuga / evento.ts

evento is just another simple event bus library written in TypeScript

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

evento.ts

evento is just another simple event bus library written in TypeScript

Oh how do I install this ?

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();

on listens to events

EventBus.on('stuff', (payload: any) => {
 console.log(payload);
});

once listens just once

EventBus.once('stuff', (payload: any) => {
 console.log(payload);
});

off removes the listener

// Somewhere in your code
EventBus.off('stuff', callback);

dispatch fires an event

// Somewhere in your code
EventBus.dispatch('stuff', 'take this!');

unsubscribe ? similar to off easy way to remove listener

const unsubscribe = EventBus.on('stuff', (payload: any) => {
  console.log(payload);
});
unsubscribe();

About

evento is just another simple event bus library written in TypeScript


Languages

Language:JavaScript 53.1%Language:TypeScript 46.9%