Skip to content

src.core.eventmanager

secretrobotron edited this page Dec 10, 2012 · 2 revisions

#EventManager (Module)

An event management system.

@expose: extend

Usage:

var EventManager = require('path/to/module/eventmanager.js');

#EventManager::ButterEvent (private Class)

An event to propagate within Butter which holds and protects data about the event instance. Propagation of the event can be stopped in the same manner as DOM events: by calling event.stopPropagation inside a handler, the dispatch loop will be interrupted.

  • type [ String ]: Event type. Usually specified by a call to object.dispatch.
  • target [ Object ]: The event target. Usually the object which dispatched the event.
  • data [ * ]: Optional. Data to accompany the event.

Usage:

var b = new ButterEvent(type, target, data);

##EventManager::ButterEvent::clone (Member Function)

Clones the event object using the stored data, type, and target as params for the new object.

Usage:

b.clone();

##EventManager::ButterEvent::stopPropagation (Member Function)

Stops the propagation of this event during a dispatch. As a side-effect _propagationStopped is set to true and cannot be reset, thus notifying external bodies that the event dispatch should halt.

Usage:

b.stopPropagation();

#EventManager::EventManagerWrapper (public Class)

EventManagerWrapper objects maintain a few internal items. First, a list of listeners is kept for this object's events. Second, all event names are namespaced so there is no leakage into other event sources. Third, an event handler is created, which has access to the appropriate listeners.

  • object [ Object ]: Object to wrap with event management functionality.

Usage:

EventManager.extend(object);

##EventManager::EventManagerWrapper::chain (public Member Function)

Attaches event listeners in such a way that they are automatically re-dispatched by the parent object when the specified child object dispatches one.

  • eventManagerWrappedObject [ EventManagerWrapper ]: Object which will dispatch desired events.
  • events [ Array ]: Array of event names to re-dispatch when eventManagerWrappedObject dispatches them.

Usage:

object.chain(eventManagerWrappedObject, events);

##EventManager::EventManagerWrapper::dispatch (public Member Function)

Dispatches an event to listeners.

  • eventName [ String ]: Name of event to dispatch.
  • eventData [ Object ]: Object containing event-specific data. Will be received by listeners.

Usage:

object.dispatch(eventName, eventData);

##EventManager::EventManagerWrapper::listen (public Member Function)

Attaches a listener for a specified event.

  • eventName [ String ]: Name of event for which the specified listener should be called.
  • listener [ Function ]: Function to call when specified event is dispatched.

Usage:

object.listen(eventName, listener);

##EventManager::EventManagerWrapper::unchain (public Member Function)

Detaches event listeners attached using chain.

  • eventManagerWrappedObject [ EventManagerWrapper ]: Previously chained object.
  • events [ Array ]: Array of event names to unchain.

@see: EventManager::EventManagerWrapper::chain

Usage:

object.unchain(eventManagerWrappedObject, events);

##EventManager::EventManagerWrapper::unlisten (public Member Function)

Detaches a listener for a specified event.

  • eventName [ String ]: Name of event from which the specified listener should be disengaged.
  • listener [ Function ]: Function to disengage.

@see: EventManager::EventManagerWrapper::listen

Usage:

object.unlisten(eventName, listener);
Clone this wiki locally