From 5280d07badbe9146994c61e1a373801c2d766b5d Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Sat, 23 Mar 2019 12:51:13 -0400 Subject: [PATCH] Remove lodash reject (re: #6087) --- modules/actions/merge_remote_changes.js | 8 ++------ modules/core/history.js | 3 +-- modules/osm/relation.js | 9 ++------- modules/presets/index.js | 6 ++++-- modules/svg/layers.js | 3 +-- modules/ui/fields/combo.js | 10 +++++++--- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/modules/actions/merge_remote_changes.js b/modules/actions/merge_remote_changes.js index 40cf19035..69f4a43d6 100644 --- a/modules/actions/merge_remote_changes.js +++ b/modules/actions/merge_remote_changes.js @@ -1,7 +1,6 @@ import _isEqual from 'lodash-es/isEqual'; import _isFunction from 'lodash-es/isFunction'; import _map from 'lodash-es/map'; -import _reject from 'lodash-es/reject'; import _union from 'lodash-es/union'; import _uniq from 'lodash-es/uniq'; import _without from 'lodash-es/without'; @@ -158,10 +157,6 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser function mergeTags(base, remote, target) { - function ignoreKey(k) { - return dataDiscarded[k]; - } - if (_option === 'force_local' || _isEqual(target.tags, remote.tags)) { return target; } @@ -173,7 +168,8 @@ export function actionMergeRemoteChanges(id, localGraph, remoteGraph, formatUser var o = base.tags || {}; var a = target.tags || {}; var b = remote.tags || {}; - var keys = _reject(_union(Object.keys(o), Object.keys(a), Object.keys(b)), ignoreKey); + var keys = _union(Object.keys(o), Object.keys(a), Object.keys(b)) + .filter(function(k) { return !dataDiscarded[k]; }); var tags = Object.assign({}, a); // shallow copy var changed = false; diff --git a/modules/core/history.js b/modules/core/history.js index 3308753c3..c44c20de2 100644 --- a/modules/core/history.js +++ b/modules/core/history.js @@ -8,7 +8,6 @@ import _isEmpty from 'lodash-es/isEmpty'; import _forEach from 'lodash-es/forEach'; import _map from 'lodash-es/map'; import _omit from 'lodash-es/omit'; -import _reject from 'lodash-es/reject'; import _without from 'lodash-es/without'; import _uniq from 'lodash-es/uniq'; @@ -503,7 +502,7 @@ export function coreHistory(context) { var osm = context.connection(); var baseWays = baseEntities.filter(function(e) { return e.type === 'way'; }); var nodes = _flatten(_uniq(_map(baseWays, 'nodes'))); - var missing = _reject(nodes, function(n) { return _stack[0].graph.hasEntity(n); }); + var missing = nodes.filter(function(n) { return !_stack[0].graph.hasEntity(n); }); if (!_isEmpty(missing) && osm) { loadComplete = false; diff --git a/modules/osm/relation.js b/modules/osm/relation.js index 441595723..2cd954cbe 100644 --- a/modules/osm/relation.js +++ b/modules/osm/relation.js @@ -1,15 +1,10 @@ import _map from 'lodash-es/map'; -import _reject from 'lodash-es/reject'; import { geoArea as d3_geoArea } from 'd3-geo'; import { osmEntity } from './entity'; import { osmJoinWays } from './multipolygon'; -import { - geoExtent, - geoPolygonContainsPolygon, - geoPolygonIntersectsPolygon -} from '../geo'; +import { geoExtent, geoPolygonContainsPolygon, geoPolygonIntersectsPolygon } from '../geo'; export function osmRelation() { @@ -162,7 +157,7 @@ Object.assign(osmRelation.prototype, { removeMembersWithID: function(id) { - var members = _reject(this.members, function(m) { return m.id === id; }); + var members = this.members.filter(function(m) { return m.id !== id; }); return this.update({members: members}); }, diff --git a/modules/presets/index.js b/modules/presets/index.js index cbcfc4511..82f22bbfe 100644 --- a/modules/presets/index.js +++ b/modules/presets/index.js @@ -1,7 +1,6 @@ import _bind from 'lodash-es/bind'; import _forEach from 'lodash-es/forEach'; import _isEmpty from 'lodash-es/isEmpty'; -import _reject from 'lodash-es/reject'; import _uniq from 'lodash-es/uniq'; import { dispatch as d3_dispatch } from 'd3-dispatch'; @@ -127,8 +126,11 @@ export function presetIndex(context) { all.areaKeys = function() { var areaKeys = {}; var ignore = ['barrier', 'highway', 'footway', 'railway', 'type']; // probably a line.. + // ignore name-suggestion-index and deprecated presets - var presets = _reject(_reject(all.collection, 'suggestion'), 'replacement'); + var presets = all.collection.filter(function(p) { + return !p.suggestion && !p.replacement; + }); // whitelist presets.forEach(function(d) { diff --git a/modules/svg/layers.js b/modules/svg/layers.js index 452bcc912..a892111fd 100644 --- a/modules/svg/layers.js +++ b/modules/svg/layers.js @@ -1,6 +1,5 @@ import _difference from 'lodash-es/difference'; import _map from 'lodash-es/map'; -import _reject from 'lodash-es/reject'; import { dispatch as d3_dispatch } from 'd3-dispatch'; import { select as d3_select } from 'd3-selection'; @@ -91,7 +90,7 @@ export function svgLayers(projection, context) { drawLayers.remove = function(what) { var arr = [].concat(what); arr.forEach(function(id) { - layers = _reject(layers, function(o) {return o.id === id;}); + layers = layers.filter(function(o) { return o.id !== id; }); }); dispatch.call('change'); return this; diff --git a/modules/ui/fields/combo.js b/modules/ui/fields/combo.js index e6d2668a7..0feccda8a 100644 --- a/modules/ui/fields/combo.js +++ b/modules/ui/fields/combo.js @@ -1,5 +1,4 @@ import _map from 'lodash-es/map'; -import _reject from 'lodash-es/reject'; import _remove from 'lodash-es/remove'; import _uniq from 'lodash-es/uniq'; @@ -110,9 +109,14 @@ export function uiFieldCombo(field, context) { } + // Compute the difference between arrays of objects by `value` property + // + // objectDifference([{value:1}, {value:2}, {value:3}], [{value:2}]) + // > [{value:1}, {value:3}] + // function objectDifference(a, b) { - return _reject(a, function(d1) { - return b.some(function(d2) { return d1.value === d2.value; }); + return a.filter(function(d1) { + return !b.some(function(d2) { return d1.value === d2.value; }); }); }