class EventHub

EventHub is a mixin class that provides an interface to register event listeners and fire events, thereby causing registered listeners to be applied. Since JS6 classes do not allow multiple inheritance, defining mixin classes requires trickery; Backdraft uses this trick. Accordingly EventHub is actually a function with the signature EventHub(superClass) where superClass is an optional class expression (defaults to class{}). EventHub then returns a class that implements the interface below by extending superClass.

Public Methods

advise(eventName, handler):[handle]

eventName [string]

handler [function(e)]

Registers handler so that it is applied to any event object that is applied to _applyHandlers(eventObject), where eventObject.name===eventName.

advise(eventNames, handler):[Array of handle]

eventName [Array of string]

handler [function(e)]

Registers handler so that it is applied to any event object that is applied to _applyHandlers(eventObject), where eventObject.name is contained in eventNames.

advise(hash):[Array of handle]

hash [Object]

Syntax sugar for Reflect.ownKeys(hash).map(key => this.advise(key, hash[key]))

destroyAdvise(eventName):[void]

eventName [string | undefined]

Removes all registered handlers for associated with eventName; if eventName===undefined, then removes all registered handlers.

Protected Methods

_applyHandlers(eventObject):[void]

eventObject [Object]

eventObject must contain the property name. Applies eventObject to all handlers previously registered to eventObject.name.

Private Properties

[EventHub.ppEvents] [Object]

A hash from event name to an array of listeners registered to that name via advise().

Static Properties

ppEvents [symbol]

Defines the symbol at which the private [ppEvents] property is located; See [ppEvents].