Skip to content

Instantly share code, notes, and snippets.

@sixolet
Created March 18, 2013 18:57
Show Gist options
  • Save sixolet/5189793 to your computer and use it in GitHub Desktop.
Save sixolet/5189793 to your computer and use it in GitHub Desktop.
A way of isolating dependencies. Mostly a code sketch, may eventually be part of Meteor
var isolate = function (f) {
var dep = new Deps.Dependency();
var result = Deps.nonreactive(f);
var computation = Deps.autorun(function () {
var newResult = f();
if (!EJSON.equals(result, newResult)) {
dep.changed();
computation.stop();
result = newResult;
}
});
Deps.depend(dep);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment