From e005321c3270079314991ed677d7cdd7b108cf31 Mon Sep 17 00:00:00 2001 From: power1220 Date: Tue, 7 Mar 2017 16:04:21 +0200 Subject: [PATCH] use lodash's isEqual for property comparison (#1682) exclude functions from equality checks --- package.json | 1 + src/Reducer.js | 9 ++++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index f5cb820..7ec04b6 100644 --- a/package.json +++ b/package.json @@ -37,6 +37,7 @@ } ], "dependencies": { + "lodash.isequal": "^4.5.0", "react": "^15.4.2", "react-addons-pure-render-mixin": "^15.4.2", "react-dom": "^15.4.2", diff --git a/src/Reducer.js b/src/Reducer.js index 7a27603..05d4f32 100644 --- a/src/Reducer.js +++ b/src/Reducer.js @@ -10,22 +10,21 @@ /* eslint-disable no-param-reassign */ import { Platform } from 'react-native'; +import isEqual from 'lodash.isequal'; import * as ActionConst from './ActionConst'; import { ActionMap } from './Actions'; import { assert } from './Util'; import { getInitialState } from './State'; -// WARN: it is not working correct. rewrite it. function checkPropertiesEqual(action, lastAction) { - let isEqual = true; for (const key of Object.keys(action)) { if (['key', 'type', 'parent'].indexOf(key) === -1) { - if (action[key] !== lastAction[key]) { - isEqual = false; + if (!isEqual(action[key], lastAction[key]) && (typeof action[key] !== 'function') && (typeof lastAction[key] !== 'function')) { + return false; } } } - return isEqual; + return true; } function resetHistoryStack(child) {