- Meteor Tutorial
- Meteor - Home
- Meteor - Overview
- Meteor - Environment Setup
- Meteor - First Application
- Meteor - Templates
- Meteor - Collections
- Meteor - Forms
- Meteor - Events
- Meteor - Session
- Meteor - Tracker
- Meteor - Packages
- Meteor - Core API
- Meteor - Check
- Meteor - Blaze
- Meteor - Timers
- Meteor - EJSON
- Meteor - HTTP
- Meteor - Email
- Meteor - Assets
- Meteor - Security
- Meteor - Sorting
- Meteor - Accounts
- Meteor - Methods
- Meteor - Package.js
- Meteor - Publish & Subscribe
- Meteor - Structure
- Meteor - Deployment
- Meteor - Running on mobile
- Meteor - ToDo App
- Meteor - Best Practices
- Meteor Useful Resources
- Meteor - Quick Guide
- Meteor - Useful Resources
- Meteor - Discussion
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.
meteorApp.html
<head> <title>meteorApp</title> </head> <body> <div> {{> myTemplate}} </div> </body> <template name = "myTemplate"> <button id = "myButton">CLICK ME</button> </template>
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.
meteorApp.js
if (Meteor.isClient) { var myData = 0 Session.set('mySession', myData); Tracker.autorun(function () { var sessionData = Session.get('mySession'); console.log(sessionData) }); Template.myTemplate.events({ '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.
Advertisements
To Continue Learning Please Login
Login with Google