A basic, and tiny but inspectable pub-sub event system.
const Events = new EventSub();
Events.subscribe('app_loaded', () => {
App.init();
});
Events.publish('app_loaded');
Log events any way you want with the pluggable logger;
const Events = new EventSub();
Events.logger = (action, details) => {
// use any logger you want.
console.log(action, details);
};
Events.subscribe('app_loaded', () => {
App.init();
});
# => SUBSCRIBE, {event: 'app_loaded' }
loggable events: [SUBSCRIBE, UNSUBSCRIBE, PUBLISH, FIRE]
Use a singleton instance of the event system, so that all components can use the same events bus.
~ event_bus.js
import { EventSub } from 'event_sub';
export var events = new EventSub();
~ every other file;
import events from 'event_bus'
events.subscribe('loaded', ()=>{...});
events.publish('your fancy event')