Event Handler
Introduction
'mini-event-handler' provides you with a class which you can use to construct event handlers. The returned object is provided with APIs to create events, attach listeners to the events and remove them.
Usage
Instantiate the Event Listener:
const EventCreator=require('mini-event-handler');
const eventhandler=new EventCreator();
To attach a listener:
var callback=()=>{
...
}
eventhandler.on('load',callback);
To emit an event:
eventhandler.emit('load');
To remove an Event Listener:
eventhandler.off('load',callback);
To remove an Event:
eventhandler.remove('load');
APIs:
API name | Description |
---|---|
.on( eventname , callback ) | used to attach event listeners to an event. Expects two arguments: |
eventname: < String > | |
callback: < Function > | |
.off( eventname , callback ) | used to detach event listeners from an event. Expects two arguments. |
eventname: < String > | |
callback: < Function > | |
.emit(eventname,...arguments) | used to trigger a particular event. Can pass extra arguments to be passed to callbacks. |
eventname: < String > | |
arguments: < Any > | |
.remove(eventname) | used to remove an event. |
eventname: < String > |