1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-30 18:39:51 +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) {
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) {
return cachedValue
}
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
}
}