1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-09-01 03:11:44 +02:00

Fix for memoize of recursive functions

This commit is contained in:
Soreine
2016-11-02 16:40:06 +01:00
parent a74fbd1390
commit 9e830b3c6d

View File

@@ -37,15 +37,17 @@ function memoize(object, properties) {
object[property] = function (...args) { object[property] = function (...args) {
const keys = [property, ...args, LEAF] const keys = [property, ...args, LEAF]
const cache = this.__cache = this.__cache || new Map() this.__cache = this.__cache || new Map()
const cachedValue = cache.getIn(keys, NO_SET) const cachedValue = this.__cache.getIn(keys, NO_SET)
if (cachedValue !== NO_SET) { if (cachedValue !== NO_SET) {
return cachedValue return cachedValue
} }
const value = original.apply(this, args) const value = original.apply(this, args)
this.__cache = cache.setIn(keys, value) // If `original` is recursive, it might have changed the cache,
// so read it from this.__cache
this.__cache = this.__cache.setIn(keys, value)
return value return value
} }
} }