Comparing version 0.10.1 to 0.10.2
@@ -140,4 +140,10 @@ 'use strict'; | ||
} | ||
// This is the most important method of the Entry API, because it | ||
// determines whether the cached this.value can be returned immediately, | ||
// or must be recomputed. The overall performance of the caching system | ||
// depends on the truth of the following observations: (1) this.dirty is | ||
// usually false, (2) this.dirtyChildren is usually null/empty, and thus | ||
// (3) valueGet(this.value) is usually returned without recomputation. | ||
Entry.prototype.recompute = function () { | ||
assertNotRecomputing(this); | ||
assert(!this.recomputing, "already recomputing"); | ||
if (!rememberParent(this) && maybeReportOrphan(this)) { | ||
@@ -149,3 +155,5 @@ // The recipient of the entry.reportOrphan callback decided to dispose | ||
} | ||
return recomputeIfDirty(this); | ||
return mightBeDirty(this) | ||
? reallyRecompute(this) | ||
: valueGet(this.value); | ||
}; | ||
@@ -202,49 +210,3 @@ Entry.prototype.setDirty = function () { | ||
} | ||
// This is the most important method of the Entry API, because it | ||
// determines whether the cached entry.value can be returned immediately, | ||
// or must be recomputed. The overall performance of the caching system | ||
// depends on the truth of the following observations: (1) this.dirty is | ||
// usually false, (2) this.dirtyChildren is usually null/empty, and thus | ||
// (3) this.value is usally returned very quickly, without recomputation. | ||
function recomputeIfDirty(entry) { | ||
if (entry.dirty) { | ||
// If this Entry is explicitly dirty because someone called | ||
// entry.setDirty(), recompute. | ||
return reallyRecompute(entry); | ||
} | ||
if (mightBeDirty(entry)) { | ||
var recomputing = entry.recomputing; | ||
// Since we are, in an abstract sense, recomputing the parent entry, | ||
// it's important to set entry.recomputing = true, so we don't get stuck | ||
// in an infinite loop if there's a cycle in the dirtyChildren graph. | ||
entry.recomputing = true; | ||
// Get fresh values for any dirty children, and if those values | ||
// disagree with this.childValues, mark this Entry explicitly dirty. | ||
entry.dirtyChildren.forEach(recomputeSilently); | ||
entry.recomputing = recomputing; | ||
if (entry.dirty) { | ||
// If this Entry has become explicitly dirty after comparing the fresh | ||
// values of its dirty children against this.childValues, recompute. | ||
return reallyRecompute(entry); | ||
} | ||
} | ||
return valueGet(entry.value); | ||
} | ||
function recomputeSilently(entry) { | ||
if (entry.recomputing) | ||
return; | ||
try { | ||
recomputeIfDirty(entry); | ||
} | ||
finally { | ||
// If the recomputation threw an exception, it will be cached via | ||
// entry.value. Returning here stops the exception from propagating. | ||
return; | ||
} | ||
} | ||
function assertNotRecomputing(entry) { | ||
assert(!entry.recomputing, "already recomputing"); | ||
} | ||
function reallyRecompute(entry) { | ||
assertNotRecomputing(entry); | ||
// Since this recomputation is likely to re-remember some of this | ||
@@ -251,0 +213,0 @@ // entry's children, we forget our children here but do not call |
@@ -137,4 +137,10 @@ import { Slot } from '@wry/context'; | ||
} | ||
// This is the most important method of the Entry API, because it | ||
// determines whether the cached this.value can be returned immediately, | ||
// or must be recomputed. The overall performance of the caching system | ||
// depends on the truth of the following observations: (1) this.dirty is | ||
// usually false, (2) this.dirtyChildren is usually null/empty, and thus | ||
// (3) valueGet(this.value) is usually returned without recomputation. | ||
Entry.prototype.recompute = function () { | ||
assertNotRecomputing(this); | ||
assert(!this.recomputing, "already recomputing"); | ||
if (!rememberParent(this) && maybeReportOrphan(this)) { | ||
@@ -146,3 +152,5 @@ // The recipient of the entry.reportOrphan callback decided to dispose | ||
} | ||
return recomputeIfDirty(this); | ||
return mightBeDirty(this) | ||
? reallyRecompute(this) | ||
: valueGet(this.value); | ||
}; | ||
@@ -199,49 +207,3 @@ Entry.prototype.setDirty = function () { | ||
} | ||
// This is the most important method of the Entry API, because it | ||
// determines whether the cached entry.value can be returned immediately, | ||
// or must be recomputed. The overall performance of the caching system | ||
// depends on the truth of the following observations: (1) this.dirty is | ||
// usually false, (2) this.dirtyChildren is usually null/empty, and thus | ||
// (3) this.value is usally returned very quickly, without recomputation. | ||
function recomputeIfDirty(entry) { | ||
if (entry.dirty) { | ||
// If this Entry is explicitly dirty because someone called | ||
// entry.setDirty(), recompute. | ||
return reallyRecompute(entry); | ||
} | ||
if (mightBeDirty(entry)) { | ||
var recomputing = entry.recomputing; | ||
// Since we are, in an abstract sense, recomputing the parent entry, | ||
// it's important to set entry.recomputing = true, so we don't get stuck | ||
// in an infinite loop if there's a cycle in the dirtyChildren graph. | ||
entry.recomputing = true; | ||
// Get fresh values for any dirty children, and if those values | ||
// disagree with this.childValues, mark this Entry explicitly dirty. | ||
entry.dirtyChildren.forEach(recomputeSilently); | ||
entry.recomputing = recomputing; | ||
if (entry.dirty) { | ||
// If this Entry has become explicitly dirty after comparing the fresh | ||
// values of its dirty children against this.childValues, recompute. | ||
return reallyRecompute(entry); | ||
} | ||
} | ||
return valueGet(entry.value); | ||
} | ||
function recomputeSilently(entry) { | ||
if (entry.recomputing) | ||
return; | ||
try { | ||
recomputeIfDirty(entry); | ||
} | ||
finally { | ||
// If the recomputation threw an exception, it will be cached via | ||
// entry.value. Returning here stops the exception from propagating. | ||
return; | ||
} | ||
} | ||
function assertNotRecomputing(entry) { | ||
assert(!entry.recomputing, "already recomputing"); | ||
} | ||
function reallyRecompute(entry) { | ||
assertNotRecomputing(entry); | ||
// Since this recomputation is likely to re-remember some of this | ||
@@ -248,0 +210,0 @@ // entry's children, we forget our children here but do not call |
{ | ||
"name": "optimism", | ||
"version": "0.10.1", | ||
"version": "0.10.2", | ||
"author": "Ben Newman <ben@benjamn.com>", | ||
@@ -5,0 +5,0 @@ "description": "Composable reactive caching with efficient invalidation.", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
106716
1048