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 byTracker.autorun. Code inside this context automatically tracks dependencies:
Dependencies
Reactive data sources useTracker.Dependency to notify computations:
API Reference
Tracker.autorun()
Run a function now and rerun whenever dependencies change:Function to run in reactive context. Receives the Computation object.
Optional configuration
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: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
Related Packages
reactive-var
Single reactive values
reactive-dict
Reactive key-value dictionaries
mongo
Reactive database queries
session
Global reactive state (deprecated)