Documentation

class ObservableObject

The base class of all observable objects, which can be placed into a tree structure to enable event handling and data binding.

class ObservableObject;

Description

The ObservableObject class is the core construct that powers framework concepts such as event handling and property binding. Many of the other classes are derived from ObservableObject, including ObservableList. This class provides the following features:

Object lifecycle — The unlink() method marks an object as stale, and disables the other features below. Objects can add additional lifecycle behavior by overriding the beforeUnlink() method.

Attaching objects — Observable objects are meant to be linked together to form a directed graph, i.e. a tree structure where one object can be ‘attached’ to only one other observable object: its parent, origin, or containing object. In turn, several objects can be attached to every object, which makes up a hierarchical structure.

Events — The emit() method ‘emits’ an event from an observable object. Events are instances of ObservableEvent, which can be handled using a callback provided to the listen() or ObservableObject.attach() methods. Typically, events are handled by their parent object (the object they’re attached to). This enables event propagation, where events emitted by an object such as a UIButton are handled by an observable object further up the tree — such as an Activity.

Property bindings — Whereas events typically flow ‘up’ a tree towards containing objects, data from these objects can be bound so that it makes its way ‘down’. In practice, this can be used to update properties automatically, such as the text of a UIText object when a corresponding property is set on an Activity. Refer to Binding for details.

Constructor

Type members

Static members

Instance members