Meteor - Tracker

Tracker is a small library used for auto updating templates once the Session variable has changed. In this chapter, we will learn how the tracker works.

First, we will create a button that will be used for updating the session.


      {{> myTemplate}}
<template name = "myTemplate">
   <button id = "myButton">CLICK ME</button>

Next, we will set the starting session value myData and create a mySession object. Tracker.autorun method is used for keeping an eye on mySession. Whenever this object changes, the template will auto-update. To test it, we will set a click event for updating.


if (Meteor.isClient) {
   var myData = 0
   Session.set('mySession', myData);

   Tracker.autorun(function () {
      var sessionData = Session.get('mySession');

      'click #myButton': function() {
         Session.set('mySession', myData ++);

If we click the CLICK ME button five times, we will see that the tracker is logging new values every time the session updates.

Meteor Tracker Log
Kickstart Your Career

Get certified by completing the course

Get Started