Class: HasEventsMixin

(abstract) HasEventsMixin

HasEventsMixin provides DOM-like asynchronous event processing for classes.
Source:
Examples

Define Events on your class

class GameEngine {
	constructor() {
		// Has Events
		HasEventsMixin(this, options)

		...

		// Events
		this.defineEvents(['running','mouseup','mousedown','mousemove','resize'])
	}
}

Bind to events

var x1 = new GameEngine()

x1.on('running',(ge, isRunning) => {
	console.log("GameEngine >", ge, isRunning ? 'running' : 'stopped')
})

Trigger Events

this.trigger('running', this, true)

Methods

(static) init()

Initialise the events subsystem.
Source:

addEventListener(event, fn)

addEventListener is an alias of HasEventsMixin#on
Parameters:
Name Type Description
event String The name of the event
fn function The event handler
Source:
Throws:
'unon: no such event ' if event not defined
Type
Exception

defineEvent(event)

Add the given event.
Parameters:
Name Type Description
event Array.<String> The event name to add
Source:

defineEvents(events)

Add the given events.
Parameters:
Name Type Description
events Array.<String> The event names to add
Source:

getEventListeners() → {Array.<function()>}

Return an array of the handlers for the given event.
Source:
Throws:
'getEventListeners: no such event ' if event not defined
Type
Exception
Returns:
The handler Functions for the event
Type
Array.<function()>

on(event, fn)

Add the given handler to the event.
Parameters:
Name Type Description
event String The name of the event
fn function The event handler
Source:
Throws:
'unon: no such event ' if event not defined
Type
Exception

removeEventListener(event, fn)

removeEventListener is an alias of HasEventsMixin#on
Parameters:
Name Type Description
event String The name of the event
fn function The event handler
Source:
Throws:
'unon: no such event ' if event not defined
Type
Exception

trigger(event, …args)

Trigger the given event with the specified arguments. Handlers are queued for execution using setImmediate().
Parameters:
Name Type Attributes Description
event String The name of the event
args * <repeatable>
The event arguments
Source:
Throws:
'trigger: no such event ' if event not defined
Type
Exception

undefineEvent(event)

Remove the given event.
Parameters:
Name Type Description
event Array.<String> The event name to remove
Source:

undefineEvents(events)

Remove the given events.
Parameters:
Name Type Description
events Array.<String> The event names to remove
Source:

unon(event, fn)

Remove the given handler from the event.
Parameters:
Name Type Description
event String The name of the event
fn function The event handler
Source:
Throws:
'unon: no such event ' if event not defined
Type
Exception