Skip to content

Instantly share code, notes, and snippets.

@ccorcos
Created March 9, 2015 00:34
Show Gist options
  • Save ccorcos/6cf8c9b44bd4ce836c39 to your computer and use it in GitHub Desktop.
Save ccorcos/6cf8c9b44bd4ce836c39 to your computer and use it in GitHub Desktop.
How to use tracker autorun to queue up events
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