A simple event driven messaging framework for javascript.
This is the heart of the system, it allows you to raise and hook to events while passing messages through your system.
hook(eventName: string, onRaise: Function): () => void
will register a delegate to be invoked upon raising the event and then return a cancelation function that can be called to remove the hook that was just registered.
raise(eventToRaise: string, data: Object): void
will raise an event passing the expected data along to each of the delegates registered to the event.
register(eventsToRegister: string/Object/string[]): void
allows you to register events, although this step may seem unnecessary i have found it very useful in diagnosing typos in event names.
getAvailableEvents(): string[]
allows you to see all currently registered events, this is mostly used for diagnostics.
A little logging tool to allow for a console log stream of the events passing through the system. Simply tell it to
startBarking()
These events give you access points to have logic run across all commands at different points in the life cycle.
This we have removed the dependency on underscore, this has a few effects:
- We are now using
Array.prototype.map()
,Array.prototype.indexOf
, andObject.keys
. Consult Can I Use, ES5 for compatibility - You can now choose how you reference underscore, should you choose too.
- Removes a heafty dependency in simple scenarios.
- Our project is written in typescript but compiled to target ECMAScript v5.
- Currently depends on Underscore.js for some utilities with a terse syntax, as needed the project can be migrated off of it.
- Uses the ILogR interface for logging. Check out my ILogR project for an implementation with some jazz :D