Created
March 9, 2015 00:34
-
-
Save ccorcos/6cf8c9b44bd4ce836c39 to your computer and use it in GitHub Desktop.
How to use tracker autorun to queue up events
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var a = {} | |
var b = new ReactiveVar(1); | |
var c = new ReactiveVar(2); | |
var needsUpdate = new Tracker.Dependency() | |
Tracker.autorun(function(){ | |
a.b = b.get() | |
needsUpdate.changed() | |
}) | |
Tracker.autorun(function(){ | |
a.c = c.get() | |
needsUpdate.changed() | |
}) | |
Tracker.autorun(function(c){ | |
needsUpdate.depend() | |
Tracker.afterFlush(function() { | |
console.log("update", a) | |
}) | |
}) | |
// try just one at a time | |
b.set(3) | |
// then try this one | |
c.set(4) | |
// now try both of these | |
b.set(5) | |
c.set(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment