Eventish
Eventish is a lightweight NodeJS library, wrapping over the low-level EventEmitter API for handling events. Set up your events using different formats and trigger them in any convenient format of your choice
It was inspired by Adebayoh Shalvah's burns library for event set-up and broadcasting.
What you get
- A flexible wrapper over raw NodeJS EventEmitter API
- Asychronous handling of events i.e if you so choose
- The ability to add event handlers in different formats and any where in your code
- Default event handlers for a group of events
- The ability to trigger events in any format of your choice
How to use
npm install --save eventish
const eventish = ;
Define an event handler:
// event_handlers/member.js { mailer;} { mailer} { mailer;}
Register the event and attach the handler:
var new_member = ; // we can use an object of events and their corresponding handlerseventish; // we can also pass two arguments to the the eventish.setEvent method, any of the event an its array of handlers or the event and its single handler or an array of events and their generic handler. They are shown below: eventish; // event and its handler eventish // an event and its array of handlers eventish;
You can trigger the events any time any where in your code.
eventish;
Setting up events
Setting up events is very easy. You call the set_event
method with an event name with the corresponding handler function in any of the following forms.
eventish eventish; // event and its handler eventish;
Handlers definition
Handlers are the agents that do work whenever any of the events you set up are triggered. They are normal functions that receive optional data arguments on triggering of the event.
{ mailer; console;}
Setting a default event handler for a group of events
It is possible to specify a all_events_handler
. Eventish will set an event handler for a group of events in an array
{ console}eventish; // when you trigger the above events, the `all_events_handler` would be called
Triggering events
In order to trigger an event, call trigger_event
with the name of the event:
eventish;
You may also pass in a payload containing data to be transmitted with the event:
eventish;
or an array of events may be passed in at ones
eventish;
or you may pass in an object of events and their corresponding data as follows:
eventish;
Asynchronous form
It is possible to pass an optional options
object as a parameter to set if you want the handler to be called asynchronously. That feature is yet to be implemented
Contributing
In case you have any ideas, features you would like to be included or any bug fixes, you can send a PR.
(Requires Node v6 or above)
- Clone the repo
git clone https://github.com/ChukwuEmekaAjah/eventish.git
Work still to be done
- add support for asychronous handler calling with an options object