Skip to content

Latest commit

 

History

History
78 lines (56 loc) · 3.63 KB

docs.md

File metadata and controls

78 lines (56 loc) · 3.63 KB

EventBus

EventBus is a bus for subscribing to and emitting events.

Kind: global class

new EventBus()

Creates an event bus.

eventBus.on([target], events, handler, [namespace]) ⇒ this

Attach an event handler function for one or more events.

Kind: instance method of EventBus

Param Type Description
[target] object An optional target object. The handler will only be called if target matches the target of the emitted event.
events string One or more space-separated events (eg. 'disconnect'). Null or empty means any event.
handler eventCallback A function to execute when the event is emitted.
[namespace] string Namespace string that will be added, separated with a dot, to every event name. If no events is null, only events with that namespace will be affected.

eventBus.off([target], events, [handler], [namespace], [strict]) ⇒ this

Remove an event handler.

Kind: instance method of EventBus

Param Type Description
[target] object An optional target object. The handler will only be removed if target matches the target of the handler.
events string One or more space-separated events (eg. 'disconnect'). Null or empty means any event.
[handler] function An option handler function. The handler will only be remove if it is the same handler.
[namespace] string Namespace string that will be added, separated with a dot, to every event name.
[strict] boolean Flag for strict mode where an error will be thrown if the handler doesn't exist.

eventBus.emit([target], event, [data], [namespace]) ⇒ this

Emits an event and triggers the base handler to be called, followed by any other handler bound.

Kind: instance method of EventBus

Param Type Description
[target] object Target object of the event
event string Name of the event. May include the namespace, if the namespace parameter is not provided.
[data] object Event data object. May be modified by the base handler, but shouldn't be changed any other handler.
[namespace] string Namespace string that will be added, separated with a dot, before the event name.

EventBus~eventCallback : function

Event callback

Kind: inner typedef of EventBus

Param Type Description
data object Event data object
target object Target object
event string Event name including namespace
action string Event action. This is the suffix of the event being listened to, or null if listening to the actual event.