Namespace: Tracker

Tracker

Classes

Computation
A Computation object represents code that is repeatedly rerun in response to reactive data changes. Computations don't have return values; they just perform actions, such as rerendering a template on the screen. Computations are created using Tracker.autorun. Use stop to prevent further rerunning of a computation.
Dependency
A Dependency represents an atomic unit of reactive data that a computation might depend on. Reactive data sources such as Session or Minimongo internally create different Dependency objects for different pieces of data, each of which may be depended on by multiple computations. When the data changes, the computations are invalidated.

Members

(static) active :Boolean

True if there is a current computation, meaning that dependencies on reactive data sources will be tracked and potentially cause the current computation to be rerun.

Type:
  • Boolean
Source:

(static) currentComputation :Tracker.Computation

The current computation, or `null` if there isn't one. The current computation is the [`Tracker.Computation`](#tracker_computation) object created by the innermost active call to `Tracker.autorun`, and it's the computation that gains dependencies when reactive data sources are accessed.

Type:
Source:

Methods

(static) afterFlush(callback)

Schedules a function to be called during the next flush, or later in the current flush if one is in progress, after all invalidated computations have been rerun. The function will be run once and not on subsequent flushes unless `afterFlush` is called again.

Parameters:
Name Type Description
callback function A function to call at flush time.
Source:

(static) autorun(runFunc, optionsopt) → {Tracker.Computation}

Run a function now and rerun it later whenever its dependencies change. Returns a Computation object that can be used to stop or observe the rerunning.

Parameters:
Name Type Attributes Description
runFunc Tracker.ComputationFunction The function to run. It receives one argument: the Computation object that will be returned.
options Object <optional>
Properties
Name Type Description
onError function Optional. The function to run when an error happens in the Computation. The only argument it receives is the Error thrown. Defaults to the error being logged to the console.
Source:
Returns:
Type
Tracker.Computation

(static) flush()

Process all reactive updates immediately and ensure that all invalidated computations are rerun.

Source:

(static) inFlush() → {Boolean}

True if we are computing a computation now, either first time or recompute. This matches Tracker.active unless we are inside Tracker.nonreactive, which nullfies currentComputation even though an enclosing computation may still be running.

Source:
Returns:
Type
Boolean

(static) nonreactive(func)

Run a function without tracking dependencies.

Parameters:
Name Type Description
func function A function to call immediately.
Source:

(static) onInvalidate(callback)

Registers a new [`onInvalidate`](#computation_oninvalidate) callback on the current computation (which must exist), to be called immediately when the current computation is invalidated or stopped.

Parameters:
Name Type Description
callback function A callback function that will be invoked as `func(c)`, where `c` is the computation on which the callback is registered.
Source:

Type Definitions

ComputationFunction()

Parameters:
Type Description
Tracker.Computation
Source: