Skip to content

Commit 2afedd7

Browse files
committed
Replace lodash isEqual with recursive check for differences
1 parent 81aacd9 commit 2afedd7

File tree

2 files changed

+7
-9
lines changed

2 files changed

+7
-9
lines changed

package.json

-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@
99
},
1010
"author": "Matt Phillips",
1111
"license": "ISC",
12-
"dependencies": {
13-
"lodash": "^4.17.2"
14-
},
1512
"devDependencies": {
1613
"babel-cli": "^6.18.0",
1714
"babel-core": "^6.18.2",

src/index.js

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import isEqual from 'lodash/fp/isEqual';
1+
const isObject = o => typeof o === 'object';
2+
const isEmpty = o => Object.keys(o).length === 0;
23

34
const diff = (lhs, rhs) => {
4-
if (isEqual(lhs, rhs)) return {};
5+
if (lhs === rhs) return {};
56

67
if (typeof rhs !== 'object' || rhs === null) return rhs;
78

@@ -14,11 +15,11 @@ const diff = (lhs, rhs) => {
1415
return rhsKeys.reduce((acc, key) => {
1516
if (!lhs.hasOwnProperty(key)) return { ...acc, [key]: rhs[key] };
1617

17-
const lhsValue = lhs[key];
18-
const rhsValue = rhs[key];
19-
if (isEqual(lhsValue, rhsValue)) return acc;
18+
const difference = diff(lhs[key], rhs[key]);
2019

21-
return { ...acc, [key]: diff(lhsValue, rhsValue) };
20+
if (isObject(difference) && isEmpty(difference)) return acc;
21+
22+
return { ...acc, [key]: difference };
2223
}, deletedValues);
2324
};
2425

0 commit comments

Comments
 (0)