I currently have a piece of code similar to this:
Tracker.autorun(function() {
var foo = Session.get("foo")
var bar = Session.get("bar")
if (bar)
console.log("foo changed and bar is set")
else
console.log("foo changed and bar is not set")
}
This code fails because the console prints one of the foo changed messages even when only bar changes.
I have to use both foo and bar inside my Tracker.autorun(), without it running whenever bar changes, and I want to do this by telling ´Tracker´ not to track bar or if possible by asking Tracker what set off the recompute, instead of separating the function into different autorunning functions or by manually keeping tabs on what Session variables have changed.
What about this approach?
var foo;
var bar;
Tracker.autorun(function() {
foo = Session.get("foo")
bar = Session.get("bar")
});
Tracker.autorun(function() {
// Track for changes of `foo`
Session.get("foo");
if (bar)
console.log("foo changed and bar is set")
else
console.log("foo changed and bar is not set")
});
UPD. Oh, I see, you already have found a solution. Anyway, I will leave my answer here, maybe somebody will find it useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With