Comparing version 0.3.0 to 0.3.1
"use strict"; | ||
var assert = require("assert"); | ||
var getLocal = require("./local.js").get; | ||
var UNKNOWN_VALUE = Object.create(null); | ||
@@ -31,2 +32,28 @@ var emptySetPool = []; | ||
Ep.mightBeDirty = function mightBeDirty() { | ||
return this.dirty || | ||
(this.dirtyChildren && | ||
this.dirtyChildren.size > 0); | ||
}; | ||
Ep.rememberChild = function rememberChild(child) { | ||
child.parents.add(this); | ||
if (! this.childValues.has(child)) { | ||
this.childValues.set(child, UNKNOWN_VALUE); | ||
} | ||
if (child.mightBeDirty()) { | ||
this.reportDirtyChild(child); | ||
} else { | ||
this.reportCleanChild(child); | ||
} | ||
}; | ||
Ep.forgetChild = function forgetChild(child) { | ||
child.parents.delete(this); | ||
this.removeDirtyChild(child); | ||
this.childValues.delete(child); | ||
}; | ||
Ep.setDirty = function setDirty() { | ||
@@ -38,2 +65,15 @@ if (this.dirty) return; | ||
Ep.setClean = function setClean() { | ||
this.dirty = false; | ||
if (this.dirtyChildren && | ||
this.dirtyChildren.size > 0) { | ||
// This Entry may still have dirty children, in which case we can't | ||
// let our parents know we're clean just yet. | ||
return; | ||
} | ||
this.parents.forEach(reportClean, this); | ||
}; | ||
function reportDirty(parent) { | ||
@@ -49,3 +89,6 @@ parent.reportDirtyChild(this); | ||
Ep.reportDirtyChild = function reportDirtyChild(child) { | ||
// Must have called this.rememberChild(child) before calling | ||
// this.reportDirtyChild(child). | ||
assert(this.childValues.has(child)); | ||
assert(child.mightBeDirty()); | ||
@@ -70,3 +113,6 @@ if (! this.dirtyChildren) { | ||
Ep.reportCleanChild = function reportCleanChild(child) { | ||
assert(! child.dirty); | ||
// Must have called this.rememberChild(child) before calling | ||
// this.reportCleanChild(child). | ||
assert(this.childValues.has(child)); | ||
assert(! child.mightBeDirty()); | ||
this.childValues.set(child, child.value); | ||
@@ -90,11 +136,3 @@ this.removeDirtyChild(child); | ||
this.maybeReportClean(); | ||
}; | ||
Ep.maybeReportClean = function maybeReportClean() { | ||
if (this.dirty || (this.dirtyChildren && | ||
this.dirtyChildren.size > 0)) { | ||
// This Entry is still not clean, either because it's explicitly dirty | ||
// or because it still has dirty children, so we can't report it as | ||
// clean to its parents. | ||
if (this.dirty || dc) { | ||
return; | ||
@@ -106,2 +144,10 @@ } | ||
Ep.rememberParent = function rememberParent() { | ||
var local = getLocal(); | ||
var parent = local.currentParentEntry; | ||
if (parent) { | ||
parent.rememberChild(this); | ||
} | ||
}; | ||
// This is the most important method of the Entry API, because it | ||
@@ -114,2 +160,4 @@ // determines whether the cached entry.value can be returned immediately, | ||
Ep.recomputeIfDirty = function recomputeIfDirty() { | ||
this.rememberParent(); | ||
if (this.dirty) { | ||
@@ -147,4 +195,2 @@ // If this Entry is explicitly dirty because someone called | ||
var getLocal = require("./local.js").get; | ||
Ep.recompute = function recompute() { | ||
@@ -159,10 +205,5 @@ this.forgetChildren(); | ||
this.value = this.fn.apply(null, this.args); | ||
} finally { | ||
assert.strictEqual(local.currentParentEntry, this); | ||
local.currentParentEntry = oldParentEntry; | ||
if (oldParentEntry) { | ||
this.parents.add(oldParentEntry); | ||
} | ||
} | ||
@@ -176,12 +217,6 @@ | ||
this.setDirty(); | ||
} else { | ||
// If we successfully recomputed this.value and did not fail to | ||
// (re)subscribe, then this Entry is no longer explicitly dirty. | ||
this.dirty = false; | ||
// However, this Entry may still have dirty children, so even though | ||
// there's a chance we can let our parents know we're clean, it's best | ||
// to let this.maybeReportClean() decide. | ||
this.maybeReportClean(); | ||
this.setClean(); | ||
} | ||
@@ -202,8 +237,2 @@ | ||
Ep.forgetChild = function forgetChild(child) { | ||
child.parents.delete(this); | ||
this.childValues.delete(child); | ||
this.removeDirtyChild(child); | ||
}; | ||
Ep.dispose = function dispose() { | ||
@@ -210,0 +239,0 @@ // If we're no longer going to be subscribed to changes affecting this |
{ | ||
"name": "optimism", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": "Ben Newman <ben@benjamn.com>", | ||
@@ -5,0 +5,0 @@ "description": "Composable reactive caching with efficient invalidation.", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11853
292