Class: Computation

Tracker.Computation()

new 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.

Source:

Members

firstRun :Boolean

True during the initial run of the computation at the time `Tracker.autorun` is called, and false on subsequent reruns and at other times.

Type:
  • Boolean
Source:

invalidated :Boolean

True if this computation has been invalidated (and not yet rerun), or if it has been stopped.

Type:
  • Boolean
Source:

stopped

True if this computation has been stopped.

Source:

Methods

flush()

Process the reactive updates for this computation immediately and ensure that the computation is rerun. The computation is rerun only if it is invalidated.

Source:

invalidate()

Invalidates this computation so that it will be rerun.

Source:

onInvalidate(callback)

Registers `callback` to run when this computation is next invalidated, or runs it immediately if the computation is already invalidated. The callback is run exactly once and not upon future invalidations unless `onInvalidate` is called again after the computation becomes valid again.

Parameters:
Name Type Description
callback function Function to be called on invalidation. Receives one argument, the computation that was invalidated.
Source:

onStop(callback)

Registers `callback` to run when this computation is stopped, or runs it immediately if the computation is already stopped. The callback is run after any `onInvalidate` callbacks.

Parameters:
Name Type Description
callback function Function to be called on stop. Receives one argument, the computation that was stopped.
Source:

run()

Causes the function inside this computation to run and synchronously process all reactive updtes.

Source:

stop()

Prevents this computation from rerunning.

Source: