[INACTIVE] This library is no longer active. For an alternative take a look at RxJs.
cobu-eventbus
cobu-eventbus is a simple, lightweight and flexible JavaScript library to manage events. It works using strings or objects (even 'strong typed') as events. You define what an event is, cobu-eventbus will support it.
The purpose of an event bus is to decouple components. This pattern is very important for large scale JavaScript applications to be maintainable.
Getting started
npm install cobu-eventbus
Examples
Simple scenario using a string as an event.
// Create the EventBus instance.var eventBus = ; // Create an callback function that can handle the specific event. { console;} // Register the callback function to an event type.eventBus; // Post an eventeventBus;
Using an object as an event
// Create the EventBus instance.var eventBus = ; // Define a constructor function to create the helloEvent object later. { thistype = 'helloEvent'; thisname = name;} // Create an callback function that can handle the specific event type. { console;}; // Register the callback function to an event type.eventBus; // Post a new event.eventBus;
API
Statistics for nerds
Performance difference between version 0.14.0 and 1.0.0
Performance | Scenario |
---|---|
10x - 100x faster | posting an event when using a lot of context and handlers |
50% smaller | file size |
25% slower | when adding / removing an event handler |