Nation JavaScript Library v2

EventDispatcher

function
EventDispatcher()

Dependencies:

None

About:

Enables any class to dispatch custom events, and adds addListener and removeListener methods to enable any parent class to listen for those custom events

addListener

method
EventDispatcher.prototype.addListener()

Option name Type Description
eventNames string

One or more event names, separated by spaces

callback function

The callback method to run when the event fires

Add a listener for a custom event, and run a callback when the event fires

removeListener

method
EventDispatcher.prototype.removeListener()

Option name Type Description
eventNames string

One or more event names, separated by spaces, to stop listening for

callback function

The callback method that was due to run. If this argument is blank, all listeners for the event name will be removed

Remove a listener for a custom event

trigger

method
EventDispatcher.prototype.trigger()

Option name Type Description
eventName string

The name of the event to fire. Can be multiple event names separated by spaces

Fire one or more custom events