Skip to content

Commit

Permalink
Eliminate lodash.isequal dependency (mapbox#5979)
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh authored and mourner committed Jan 11, 2018
1 parent 7412c0f commit 7e90b9f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 42 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"gray-matter": "^3.0.8",
"grid-index": "^1.0.0",
"jsonlint-lines-primitives": "~1.6.0",
"lodash.isequal": "^3.0.4",
"minimist": "0.0.8",
"package-json-versionify": "^1.0.2",
"pbf": "^3.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/style-spec/diff.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

const isEqual = require('lodash.isequal');
const isEqual = require('./util/deep_equal');

const operations = {

Expand Down
1 change: 0 additions & 1 deletion src/style-spec/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"csscolorparser": "~1.0.2",
"in-publish": "^2.0.0",
"jsonlint-lines-primitives": "~1.6.0",
"lodash.isequal": "^3.0.4",
"minimist": "0.0.8",
"rw": "^1.3.3",
"sort-object": "^0.3.2",
Expand Down
28 changes: 28 additions & 0 deletions src/style-spec/util/deep_equal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @flow

/**
* Deeply compares two object literals.
*
* @private
*/
function deepEqual(a: ?mixed, b: ?mixed): boolean {
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i])) return false;
}
return true;
}
if (typeof a === 'object' && a !== null && b !== null) {
if (!(typeof b === 'object')) return false;
const keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
for (const key in a) {
if (!deepEqual(a[key], b[key])) return false;
}
return true;
}
return a === b;
}

module.exports = deepEqual;
25 changes: 1 addition & 24 deletions src/util/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,30 +288,7 @@ exports.filterObject = function(input: Object, iterator: Function, context?: Obj
return output;
};

/**
* Deeply compares two object literals.
*
* @private
*/
exports.deepEqual = function(a: ?mixed, b: ?mixed): boolean {
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) return false;
for (let i = 0; i < a.length; i++) {
if (!exports.deepEqual(a[i], b[i])) return false;
}
return true;
}
if (typeof a === 'object' && a !== null && b !== null) {
if (!(typeof b === 'object')) return false;
const keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) return false;
for (const key in a) {
if (!exports.deepEqual(a[key], b[key])) return false;
}
return true;
}
return a === b;
};
exports.deepEqual = require('../style-spec/util/deep_equal');

/**
* Deeply clones two objects.
Expand Down
15 changes: 0 additions & 15 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6205,14 +6205,6 @@ lodash._basefor@^3.0.0:
version "3.0.3"
resolved "https://registry.yarnpkg.com/lodash._basefor/-/lodash._basefor-3.0.3.tgz#7550b4e9218ef09fad24343b612021c79b4c20c2"

lodash._baseisequal@^3.0.0:
version "3.0.7"
resolved "https://registry.yarnpkg.com/lodash._baseisequal/-/lodash._baseisequal-3.0.7.tgz#d8025f76339d29342767dcc887ce5cb95a5b51f1"
dependencies:
lodash.isarray "^3.0.0"
lodash.istypedarray "^3.0.0"
lodash.keys "^3.0.0"

lodash._basetostring@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/lodash._basetostring/-/lodash._basetostring-3.0.1.tgz#d1861d877f824a52f669832dcaf3ee15566a07d5"
Expand Down Expand Up @@ -6287,13 +6279,6 @@ lodash.isarray@^3.0.0:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isarray/-/lodash.isarray-3.0.4.tgz#79e4eb88c36a8122af86f844aa9bcd851b5fbb55"

lodash.isequal@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-3.0.4.tgz#1c35eb3b6ef0cd1ff51743e3ea3cf7fdffdacb64"
dependencies:
lodash._baseisequal "^3.0.0"
lodash._bindcallback "^3.0.0"

lodash.isequal@^4.0.0:
version "4.5.0"
resolved "https://registry.yarnpkg.com/lodash.isequal/-/lodash.isequal-4.5.0.tgz#415c4478f2bcc30120c22ce10ed3226f7d3e18e0"
Expand Down

0 comments on commit 7e90b9f

Please sign in to comment.