From 9e830b3c6d6efe5056b7ed282931cc1571f3e778 Mon Sep 17 00:00:00 2001 From: Soreine Date: Wed, 2 Nov 2016 16:40:06 +0100 Subject: [PATCH] Fix for memoize of recursive functions --- src/utils/memoize.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/memoize.js b/src/utils/memoize.js index ce328329e..8908446b6 100644 --- a/src/utils/memoize.js +++ b/src/utils/memoize.js @@ -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 } }