Mixin: Observable

Defined in: src/mixin/observable.coffee

Overview

Implementation of the Observable pattern. Allows other objects to observe events sent by this one. Override {#notifyObserverer notifyObserver} to send custom data to your observers, and {#notifiableEvents notifiableEvents} to determine the events which can be observed.

Method Summary

Method Details

? (void) attachObserver(observer, events)

Attach an observer to listen for a given event.

@throws [Error] If the event is not in {#notifiableEvents notifiableEvents}

Parameters:

  • observer (Object) An object implementing the method notify()
  • events (String/Array) An event or set of events to observe

? (void) detachObserver(observer, events)

Detach an observer (i.e., stop the observer listening to the given event).

Parameters:

  • observer (Object) An observing object
  • events (String/Array) An event or set of events being observed

? (void) notifyObserver(observer, event, data)

Notify an observer of a given event, optionally passing data. Called by the private method notify, which notifies all observers. Override this method to pass your own custom data.

Parameters:

  • observer (Object) An observing object, which must implement the notify method
  • event (String) The event being notified
  • data (Object) Data to be sent with the event

? (void) notify(event, data = {}) (private)

? (void) addObserver(observer, event) (private)

? (void) removeObserver(observer, collection) (private)