Introducing Deps

The Meteor reactivity system has been cleaned up and improved in the new `Deps` package

Start Watching Loading...

Want more? Check out the Evented Mind class this lesson was take from:

Meteor Reactivity with Deps

Check it Out

Introducing Deps

The Meteor reactivity system has been cleaned up and improved in the new `Deps` package. In this video we'll revisit what it means to be "reactive" and I'll illustrate how to use the `Deps.autorun` and `Deps.flush` methods.

  • #Meteor
<p class="code-block-title">introducing-deps.js</p> ```javascript if (Meteor.isClient) { counter = 1; updateName = function () { // Change a reactive data source value Session.set("name", "Chris " + counter++); // Force the dependent functions to run again // instead of waiting for this function to complete first Deps.flush(); // The printName functions should execute before // this console.log since we called Deps.flush() console.log("After the Session.set('name')"); }; // Both of these functions depend on the reactive // data source Session.get("name") printName = function () { console.log("1. The name is: ", Session.get("name")); }; printNameAgain = function () { console.log("2. The name is: ", Session.get("name")); }; // Rerun printName if Session.get("name") changes Deps.autorun(printName); // Also rerun printNameAgain if Session.get("name") changes Deps.autorun(printNameAgain); } ```