2 Observables
An observable holds a value plus a set of subscribers that are known as observers. When the value in an observable changes, observers are notified.
Besides registering observers directly, an application can provide an observable instead of an immediate value when constructing a view; each rendering of the view then becomes and observer that reacts to changes in the observable’s value. For example, the label or enable state for a button view can be supplied as an observable, and if the observable’s value changes from #true to #false, then a button (or, more precisely, a button in a GUI rendered from the view) becomes disabled.
class | ||||
| ||||
| ||||
annotation | ||||
| ||||
| ||||
annotation | ||||
| ||||
| ||||
annotation | ||||
| ||||
| ||||
annotation | ||||
| ||||
| ||||
annotation | ||||
| ||||
| ||||
annotation | ||||
|
The annotation Obs.of(annot) is satisfied by an annotation whose value satisfies annot. The predicate and conversion (if any) associated with annot is not applied immediately, but it is applied every time a value is extracted or put into the observable. The annotation ObsOrValue.of(annot) is satisfied by a value that satisfies either annot or Obs.of(annot).
The Obs.now_of(annot) annotation is Obs.of(annot), but the current value in the observable is checked immediately, and it is not checked later or when a new value is supplied to the observable. In other words, Obs.now_of(annot) is a predicate annotation, while Obs.of(annot) is a converter annotation. The annot argument in Obs.now_of(annot) must be a predicate annotation. The ObsOrValue.now_of(annot) annotation is analogously like ObsOrValue.of(annot).
The Obs.later_of(annot) and ObsOrValue.later_of(annot) annotations are aliases for Obs.of(annot) and ObsOrValue.of(annot), respectively.
method | ||
| ||
operator | ||
Normally, instead of peeking an observable’s value, you should either register an observer or pass an observer to a constructor that expects one. For example, when an observer’s value should affect drawing in a Canvas, then the first argument to Canvas should the observer (or one derived from it), and then a rendered canvas will be updated when the observable changes.
method | ||
| ||
operator | ||
function | ||
| ||
function | ||
|