Remove lodash omit

(re: #6087)
This commit is contained in:
Bryan Housel
2019-03-26 14:11:55 -04:00
parent e916d18473
commit 4821bf0a68
10 changed files with 41 additions and 26 deletions

View File

@@ -1,6 +1,6 @@
import _groupBy from 'lodash-es/groupBy';
import _omit from 'lodash-es/omit';
import { utilObjectOmit } from '../util';
import { osmJoinWays, osmWay } from '../osm';
@@ -135,7 +135,7 @@ export function actionAddMember(relationId, member, memberIndex, insertPair) {
wayMembers.push(item.pair[0]);
wayMembers.push(item.pair[1]);
} else {
wayMembers.push(_omit(item, 'index'));
wayMembers.push(utilObjectOmit(item, ['index']));
}
}
@@ -144,7 +144,7 @@ export function actionAddMember(relationId, member, memberIndex, insertPair) {
// see https://wiki.openstreetmap.org/wiki/Public_transport#Service_routes
var newMembers = PTv2members.concat( (groups.node || []), wayMembers, (groups.relation || []) );
return graph.replace(relation.update({members: newMembers}));
return graph.replace(relation.update({ members: newMembers }));
// `moveMember()` changes the `members` array in place by splicing

View File

@@ -1,9 +1,8 @@
import _groupBy from 'lodash-es/groupBy';
import _map from 'lodash-es/map';
import _omit from 'lodash-es/omit';
import { geoPolygonContainsPolygon } from '../geo';
import { osmJoinWays, osmRelation } from '../osm';
import { utilObjectOmit } from '../util';
export function actionMergePolygon(ids, newRelationId) {
@@ -48,8 +47,8 @@ export function actionMergePolygon(ids, newRelationId) {
return polygons.map(function(d, n) {
if (i === n) return null;
return geoPolygonContainsPolygon(
_map(d.nodes, 'loc'),
_map(w.nodes, 'loc')
d.nodes.map(function(n) { return n.loc; }),
w.nodes.map(function(n) { return n.loc; })
);
});
});
@@ -108,7 +107,7 @@ export function actionMergePolygon(ids, newRelationId) {
return graph.replace(relation.update({
members: members,
tags: _omit(relation.tags, 'area')
tags: utilObjectOmit(relation.tags, ['area'])
}));
};

View File

@@ -1,11 +1,10 @@
import _omit from 'lodash-es/omit';
import _throttle from 'lodash-es/throttle';
import { select as d3_select } from 'd3-selection';
import { geoSphericalDistance } from '../geo';
import { modeBrowse } from '../modes';
import { utilQsString, utilStringQs } from '../util';
import { utilObjectOmit, utilQsString, utilStringQs } from '../util';
export function behaviorHash(context) {
@@ -21,9 +20,9 @@ export function behaviorHash(context) {
return true; // replace bogus hash
} else if (s !== formatter(map).slice(1)) { // hash has changed
var mode = context.mode(),
dist = geoSphericalDistance(map.center(), [args[2], args[1]]),
maxdist = 500;
var mode = context.mode();
var dist = geoSphericalDistance(map.center(), [args[2], args[1]]);
var maxdist = 500;
// Don't allow the hash location to change too much while drawing
// This can happen if the user accidently hit the back button. #3996
@@ -40,7 +39,7 @@ export function behaviorHash(context) {
var center = map.center();
var zoom = map.zoom();
var precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
var q = _omit(utilStringQs(window.location.hash.substring(1)),
var q = utilObjectOmit(utilStringQs(window.location.hash.substring(1)),
['comment', 'source', 'hashtags', 'walkthrough']
);
var newParams = {};

View File

@@ -7,7 +7,6 @@ import _isFunction from 'lodash-es/isFunction';
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 _uniq from 'lodash-es/uniq';
import { dispatch as d3_dispatch } from 'd3-dispatch';
@@ -19,7 +18,7 @@ import { coreGraph } from './graph';
import { coreTree } from './tree';
import { osmEntity } from '../osm/entity';
import { uiLoading } from '../ui';
import { utilRebind, utilSessionMutex } from '../util';
import { utilObjectOmit, utilRebind, utilSessionMutex } from '../util';
export function coreHistory(context) {
@@ -393,7 +392,7 @@ export function coreHistory(context) {
function customizer(src) {
var copy = _omit(_cloneDeep(src), ['type', 'user', 'v', 'version', 'visible']);
var copy = utilObjectOmit(_cloneDeep(src), ['type', 'user', 'v', 'version', 'visible']);
if (_isEmpty(copy.tags)) {
delete copy.tags;
}

View File

@@ -1,8 +1,8 @@
import _omit from 'lodash-es/omit';
import _uniq from 'lodash-es/uniq';
import { t } from '../util/locale';
import { areaKeys } from '../core/context';
import { utilObjectOmit } from '../util';
export function presetPreset(id, preset, fields, visible, rawPresets) {
@@ -183,7 +183,7 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
}
// Lookup documentation on OSM Wikibase...
var key = reference.key || Object.keys(_omit(preset.tags, 'name'))[0];
var key = reference.key || Object.keys(utilObjectOmit(preset.tags, 'name'))[0];
var value = reference.value || preset.tags[key];
if (geometry === 'relation' && key === 'type') {
@@ -205,7 +205,7 @@ export function presetPreset(id, preset, fields, visible, rawPresets) {
preset.removeTags = preset.removeTags || preset.tags || {};
preset.unsetTags = function(tags, geometry) {
tags = _omit(tags, Object.keys(preset.removeTags));
tags = utilObjectOmit(tags, Object.keys(preset.removeTags));
for (var f in preset.fields) {
var field = preset.fields[f];

View File

@@ -1,10 +1,9 @@
import _debounce from 'lodash-es/debounce';
import _forEach from 'lodash-es/forEach';
import _omit from 'lodash-es/omit';
import { json as d3_json } from 'd3-request';
import { utilQsString } from '../util';
import { utilObjectOmit, utilQsString } from '../util';
import { currentLocale } from '../util/locale';
@@ -65,7 +64,7 @@ function setSortMembers(params) {
function clean(params) {
return _omit(params, ['geometry', 'debounce']);
return utilObjectOmit(params, ['geometry', 'debounce']);
}

View File

@@ -19,6 +19,7 @@ export { utilHighlightEntities } from './util';
export { utilIdleWorker } from './idle_worker';
export { utilKeybinding } from './keybinding';
export { utilNoAuto } from './util';
export { utilObjectOmit } from './object';
export { utilPrefixCSSProperty } from './util';
export { utilPrefixDOMProperty } from './util';
export { utilPreset } from './util';

9
modules/util/object.js Normal file
View File

@@ -0,0 +1,9 @@
export function utilObjectOmit(obj, omitKeys) {
return Object.keys(obj).reduce(function(result, key) {
if (omitKeys.indexOf(key) === -1) {
result[key] = obj[key]; // keep
}
return result;
}, {});
}

View File

@@ -1,5 +1,3 @@
import _map from 'lodash-es/map';
import { t, textDirection } from './locale';
import { utilDetect } from './detect';
import { remove as removeDiacritics } from 'diacritics';
@@ -7,7 +5,9 @@ import { fixRTLTextForSvg, rtlRegex } from './svg_paths_rtl_fix';
export function utilTagText(entity) {
return _map(entity.tags, function(v, k) {
var obj = (entity && entity.tags) || {};
return Object.keys(obj).map(function(k) {
var v = obj[k];
return k + '=' + v;
}).join(', ');
}

9
test/spec/util/object.js Normal file
View File

@@ -0,0 +1,9 @@
describe('iD.utilObjectOmit', function() {
it('omits keys', function() {
var t = { a: 1, b: 2 };
expect(iD.utilObjectOmit(t, [])).to.eql({ a: 1, b: 2 });
expect(iD.utilObjectOmit(t, ['a'])).to.eql({ b: 2 });
expect(iD.utilObjectOmit(t, ['a', 'b'])).to.eql({});
});
});