Skip to content

Strongly typed Event Bus to communicate between components

License

Notifications You must be signed in to change notification settings

mingue/typed-event-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

An strongly typed EventBus

  • Simple bus for sending strongly typed events between components
  • Allows pub/sub based on message types

Usage

//Create a new EventBus, usually once per application.
let eb = new EventBus();

//Define some events to publish and subscribe on
@message //Decorate  with @message to create an event channel
class SomeEvent {
    content: string;

    constructor(content: string) {
        this.content = content;
    }
}

//Subscribe to events
let s = eb.Subscribe(SomeEvent, (e) => {
    console.log(e.content);
});

//Publish new events to the bus
eb.Publlish(new SomeEvent("Hello World!!"));

//Once finish you can unsubscribe to stop receiving messages
s.Dispose();

About

Strongly typed Event Bus to communicate between components

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published