diff --git a/src/computed-properties.js b/src/computed-properties.js index c4d4df10..3bde0a48 100644 --- a/src/computed-properties.js +++ b/src/computed-properties.js @@ -1,4 +1,4 @@ -import { areInputsEqual } from './lib'; +import { areValuesEqual } from './lib'; export function createComputedPropertyBinder(parentPath, key, def, _r) { let runOnce = false; @@ -14,7 +14,7 @@ export function createComputedPropertyBinder(parentPath, key, def, _r) { ); if ( runOnce && - (areInputsEqual(prevInputs, inputs) || + (areValuesEqual(prevInputs, inputs) || (_r._i._cS.isInReducer && new Error().stack.match(/shallowCopy/gi) !== null)) ) { @@ -24,7 +24,12 @@ export function createComputedPropertyBinder(parentPath, key, def, _r) { return prevValue; } prevInputs = inputs; - prevValue = def.fn(...inputs); + + const newValue = def.fn(...inputs); + if(!areValuesEqual(newValue, prevValue)) { + prevValue = newValue; + } + runOnce = true; return prevValue; }, diff --git a/src/lib.js b/src/lib.js index be80ddd7..26573796 100644 --- a/src/lib.js +++ b/src/lib.js @@ -175,6 +175,10 @@ export function areInputsEqual(newInputs, lastInputs) { return true; } +export function areValuesEqual(newValue, lastValue) { + return newValue === lastValue || JSON.stringify(newValue) === JSON.stringify(lastValue); +} + // export function memoizeOne(resultFn) { // let lastArgs = []; // let lastResult;