Signal
Signal is a light ~700 Bytes Singleton instance of an Event bus. It works directly in the browser or has support for commonJS and amd modules.
Its Really tiny. Check it out here;
Motivation
I got the concept of creating a unified event bus whilst reading this article. What if an app had multiple tech stacks, was there was a way to communicate between them?? This can be super useful for people migrating their stacks from one to another. A unified bus is one of the ways for microservices / micro apps to communicate with one another. Typically they follow a pub sub design pattern
Installation
Using npm
npm install signal-event yarn add signal-event
Usage
signal-event
exports a function which when invoked with a consturctor will generate the same instance every single time. Thereby keeping all your events at one place.
const Signal = ; const S1 = ;
Register An Event handler
S1;
Register Multiple Event handlers
S1;S1;S1;S1; S1 // This will get triggered in all the handlers;
Emit an Event
S1
Remove an Event Hanlder
{ // do something with data} S1; S1; S1; /** If you need to remove an event handler the function specified must have a name, annonymous arrow fn wont work S1.remove('beep', () => {}); will not work*/
Remove All event handlers for an event
S1;
API
- Add Event Listener
Signal.on(eventName, handlerFunction)
- Emit Event
Signal.emit(eventName, data)
- Remove Event Handler
Signal.remove(eventName, handlerFunction, removeAllHandlers)
Dev Setup
yarn run testyarn run cover
Liked the repo ⭐️ it.
Found any Bugs File them here