@adrianhelvik/bind
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -14,6 +14,9 @@ "use strict"; | ||
var staticSkipRecursive = false; | ||
var upToDate = 'upToDate'; | ||
var dirty = 'dirty'; | ||
var tracking = new WeakSet(); | ||
function memoize(fn) { | ||
var skipRecursive = staticSkipRecursive; | ||
var status = dirty; | ||
@@ -26,3 +29,17 @@ var removePrevious; | ||
var _track = (0, _track2["default"])(function () { | ||
value = fn(); | ||
if (tracking.has(fn)) { | ||
if (skipRecursive) { | ||
return; | ||
} | ||
throw Error('Use memoize.skipRecursive to skip recursive calls'); | ||
} | ||
tracking.add(fn); | ||
try { | ||
value = fn(); | ||
} finally { | ||
tracking["delete"](fn); | ||
} | ||
}), | ||
@@ -95,2 +112,3 @@ accessed = _track.accessed; | ||
if (skipRecursive) return; | ||
return value; | ||
@@ -100,3 +118,13 @@ }; | ||
memoize.skipRecursive = function (fn) { | ||
staticSkipRecursive = true; | ||
try { | ||
return memoize(fn); | ||
} finally { | ||
staticSkipRecursive = false; | ||
} | ||
}; | ||
var _default = memoize; | ||
exports["default"] = _default; |
{ | ||
"name": "@adrianhelvik/bind", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"main": "lib/index.js", | ||
@@ -5,0 +5,0 @@ "module": "src/index.js", |
import { manager } from './state.js' | ||
import track from './track.js' | ||
let staticSkipRecursive = false | ||
const upToDate = 'upToDate' | ||
const dirty = 'dirty' | ||
const tracking = new WeakSet() | ||
function memoize(fn) { | ||
const skipRecursive = staticSkipRecursive | ||
let status = dirty | ||
@@ -15,3 +19,14 @@ let removePrevious | ||
const { accessed } = track(() => { | ||
value = fn() | ||
if (tracking.has(fn)) { | ||
if (skipRecursive) { | ||
return | ||
} | ||
throw Error('Use memoize.skipRecursive to skip recursive calls') | ||
} | ||
tracking.add(fn) | ||
try { | ||
value = fn() | ||
} finally { | ||
tracking.delete(fn) | ||
} | ||
}) | ||
@@ -36,2 +51,3 @@ const removers = new Set() | ||
} | ||
if (skipRecursive) return | ||
return value | ||
@@ -41,2 +57,11 @@ } | ||
memoize.skipRecursive = fn => { | ||
staticSkipRecursive = true | ||
try { | ||
return memoize(fn) | ||
} finally { | ||
staticSkipRecursive = false | ||
} | ||
} | ||
export default memoize |
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
88123
51
2655