ractive.observe()
edit this pageObserves the data at a particular keypath. Unless specified otherwise, the observer will be initialised once as soon as you create the observer, with undefined as oldValue. Thereafter it will be notified whenever the observed keypath changes.
See Observers for more detail.
ractive.observe( keypath, callback[, options ])
Returns an object with a
cancelmethod, for cancelling the observerkeypath
StringThe keypath to observe. Any of the keys in this keypath can be a
*character, which is treated as a wildcard.callback
FunctionThe function that will be called, with
newValue,oldValueandkeypathas arguments (see Observers for more nuance regarding these arguments), whenever the observed keypath changes value. By default the function will be called withractiveasthisoptions
Objectinit
BooleanDefaults to
true. Whether or not to initialise the observer, i.e. call the function with the current value ofkeypathas the first argument andundefinedas the seconddefer
BooleanDefaults to
false, in which case observers will fire before any DOM changes take place. Iftrue, the observer will fire once the DOM has been updated.context
Defaults to
ractive. The context the observer is called in (i.e. the value ofthis)debug
BooleanDefaults to
false- exceptions that are thrown within observers are handled. This is useful when observing uninitialised keypaths when you don't want to litter your code withif (foo !== undefined) { /*...*/ }, but you may prefer to handle errors yourself, in which case usetrue.ractive.observe( map[, options ])
Returns an object with a
cancelmethod, for cancelling all observersmap
ObjectA map of
keypath: observerpairsoptions
ObjectAs above.