A basic, and tiny but inspectable pub-sub event system.
constEvents=newEventSub();Events.subscribe('app_loaded',()=>{App.init();});Events.publish('app_loaded');Log events any way you want with the pluggable logger;
constEvents=newEventSub();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.jsimport{EventSub}from'event_sub';exportvarevents=newEventSub();~everyotherfile;importeventsfrom'event_bus'events.subscribe('loaded',()=>{...});events.publish('your fancy event')