Skip to content
Browse files

new implementation of isolate

  • Loading branch information...
1 parent a5bac3d commit 37ace36ac95b8c5c080546ffd5d70e2b7f2c100f @dgreensp dgreensp committed
Showing with 14 additions and 11 deletions.
  1. +14 −11 packages/deps/deps.js
View
25 packages/deps/deps.js
@@ -311,18 +311,21 @@
},
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;
- }
+ if (! Deps.active)
+ return f();
+
+ var resultDep = new Deps.Dependency;
+ var origResult;
+ Deps.autorun(function (c) {
+ var result = f();
+ if (c.firstRun)
+ origResult = result;
+ else if (!EJSON.equals(result, origResult))
+ resultDep.changed();
});
- Deps.depend(dep);
- return result;
+ Deps.depend(resultDep);
+
+ return origResult;
}
});

0 comments on commit 37ace36

Please sign in to comment.
Something went wrong with that request. Please try again.