Fork me on GitHub

AFrameJS

- Javascript MVC Library

class AFrame.Observable

An Observable is the way events are done. Observables are very similar to DOM Events in that each object has a set of events that it can trigger. Objects that are concerned with a particular event register a callback to be called whenever the event is triggered. Observables allow for each event to have zero or many listeners, meaning the developer does not have to manually keep track of who to notify when a particular event happens. This completely decouples the triggering object from any objects that care about it.

Methods

Methods Returns Description
bind( callback ) id

Bind a callback to the observable

Parameters:

  • callback <function>
    • callback to register
    • Returns:

      • <id>

        id that can be used to unbind the callback. Note, all ids for all bindings are unique.

init( ) void

Initialize the observable

isTriggered( ) boolean

Check whether the observable has been triggered

Returns:

  • <boolean>

    true if observable has been triggered, false otw.

teardown( ) void

Tear the observable down, free references

trigger( optional ) void

Trigger the observable, calls any callbacks bound to the observable.

Parameters:

  • optional <variant>
    • any arguments will be passed to the callbacks
unbind( id ) void

Unbind an observable

Parameters:

  • id <id>
    • id of observable to unbind
unbindAll( ) void

Unbind all observables