eventJS library creates a pub-sub design. It enable you to use pub-sub in simplest way.
Below function to create the event
events.registerEvent(eventName)
where
- eventName: is name of event which will be created. Using the same name other compoents can subscribe to the event.
- data: is the parameter or the data which will be provided to callbacks
Below function to subscribe the event
events.on(eventName, callbackfn, {bindobj: obj})
where
- eventName: is name of event which will be subscribe. If there is no such event craeted the error will be thrown
- callbackfn: is callback function which will be called on event
- bindobj: is the object to which callback function will be bind. if it passed the callback will be called in the obj's context
Below function to subscribe the event
events.emit(eventName, data)
where
- eventName: is name of event which will be publised.
- data: is the parameters to subscribers callback. more parameter can be added after data.
Below function to subscribe the event
events.off(eventName, callbackfn)
where
- eventName: is name of event which will be unsubscribe. If there is no such event craeted the error will be thrown
- callbackfn: is callback function, which will be called on event, will get unsubscribed and will not be called on event.