Skip to content

A basic, and tiny but inspectable pub-sub event system. (Javascript)

License

Notifications You must be signed in to change notification settings

graemeworthy/EventSub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Event Sub

A basic, and tiny but inspectable pub-sub event system.

const Events = new EventSub();
Events.subscribe('app_loaded', () => {
  App.init();
});

Events.publish('app_loaded');

Inspection

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]

Singleton

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')

About

A basic, and tiny but inspectable pub-sub event system. (Javascript)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published