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
- ? (void) attachObserver(observer, events) Attach an observer to listen for a given event.
- ? (void) detachObserver(observer, events) Detach an observer (i.e., stop the observer listening to the given event).
- ? (void) notifyObserver(observer, event, data) Notify an observer of a given event, optionally passing data.
- ? (void) notify(event, data = {}) Private
- ? (void) addObserver(observer, event) Private
- ? (void) removeObserver(observer, collection) Private
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}
? (void) detachObserver(observer, events)
Detach an observer (i.e., stop the observer listening to the given event).
? (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.
? (void) notify(event, data = {}) (private)
? (void) addObserver(observer, event) (private)
? (void) removeObserver(observer, collection) (private)