Skip to main content
Tracker is Meteor’s incredibly lightweight (~1k) library for transparent reactive programming. It allows reactive data sources to automatically notify reactive consumers without manual event handling.

Installation

Tracker is included by default in Meteor applications and is the foundation of Meteor’s reactivity system.

Overview

Tracker provides:
  • Reactive Computations - Automatically rerun code when dependencies change
  • Dependency Tracking - Transparent detection of data dependencies
  • Automatic Cleanup - Proper disposal of reactive contexts
  • Minimal Overhead - Nearly zero cost when not in reactive context
  • Simple API - Just a few functions to learn

Package Information

  • Version: 1.3.4
  • Summary: Dependency tracker to allow reactive callbacks
  • Exports: Tracker, Deps (deprecated alias)
  • Size: ~1KB minified

Core Concepts

Reactive Context

A reactive context is created by Tracker.autorun. Code inside this context automatically tracks dependencies:

Dependencies

Reactive data sources use Tracker.Dependency to notify computations:

API Reference

Tracker.autorun()

Run a function now and rerun whenever dependencies change:
runFunc
function
required
Function to run in reactive context. Receives the Computation object.
options
object
Optional configuration
options.onError
function
Error handler called if the computation throws

Advanced autorun

Tracker.Computation

Represents a reactive computation:

Lifecycle Callbacks

Tracker.Dependency

Create reactive data sources:

Dependency Methods

Tracker.active

Check if currently in reactive context:

Tracker.currentComputation

Get the current computation:

Tracker.nonreactive()

Run code without establishing dependencies:

Tracker.flush()

Flush pending reactive updates immediately:
Use Tracker.flush() sparingly. It can cause performance issues and unexpected behavior.

Tracker.afterFlush()

Run callback after next flush:

Patterns and Best Practices

Pattern: Reactive Data Source

Pattern: Cleanup Resources

Pattern: Conditional Dependencies

Pattern: Throttling Reactivity

Pattern: Preventing Infinite Loops

Integration with Meteor

Reactive Data Sources in Meteor

Many Meteor APIs are Tracker-aware:

Using with Blaze Templates

Blaze automatically creates reactive contexts:

Using with React

Example: Temperature Monitor

Example: Smart Cache

Debugging

Log Computation Lifecycle

Find Reactive Dependencies

Performance Tips

Minimize computation work - Keep autoruns lightweight
Use Tracker.nonreactive() - Avoid unnecessary dependencies
Stop unused computations - Always call .stop() when done
Batch updates - Invalidate multiple dependencies before flushing

reactive-var

Single reactive values

reactive-dict

Reactive key-value dictionaries

mongo

Reactive database queries

session

Global reactive state (deprecated)

Source Code