From 3def4db09ff444e00f0f757a4ad7151489e81e2a Mon Sep 17 00:00:00 2001 From: Bryan Housel Date: Mon, 25 Sep 2017 13:58:53 -0400 Subject: [PATCH] Convert lodah-es and d3 to named imports for operations --- modules/operations/circularize.js | 9 +++++---- modules/operations/continue.js | 12 +++++++----- modules/operations/delete.js | 9 +++++---- modules/operations/disconnect.js | 11 +++++++---- modules/operations/move.js | 7 ++++--- modules/operations/orthogonalize.js | 5 +++-- modules/operations/reflect.js | 10 ++++++---- modules/operations/rotate.js | 10 ++++++---- modules/operations/split.js | 11 +++++++---- modules/operations/straighten.js | 5 +++-- 10 files changed, 53 insertions(+), 36 deletions(-) diff --git a/modules/operations/circularize.js b/modules/operations/circularize.js index a7b713bb0..5d3b26421 100644 --- a/modules/operations/circularize.js +++ b/modules/operations/circularize.js @@ -1,7 +1,8 @@ -import _ from 'lodash'; +import _uniq from 'lodash-es/uniq'; + import { t } from '../util/locale'; -import { actionCircularize } from '../actions/index'; -import { behaviorOperation } from '../behavior/index'; +import { actionCircularize } from '../actions'; +import { behaviorOperation } from '../behavior'; export function operationCircularize(selectedIDs, context) { @@ -20,7 +21,7 @@ export function operationCircularize(selectedIDs, context) { operation.available = function() { return selectedIDs.length === 1 && entity.type === 'way' && - _.uniq(entity.nodes).length > 1; + _uniq(entity.nodes).length > 1; }; diff --git a/modules/operations/continue.js b/modules/operations/continue.js index 77e45905c..53c92db7a 100644 --- a/modules/operations/continue.js +++ b/modules/operations/continue.js @@ -1,14 +1,16 @@ -import _ from 'lodash'; +import _extend from 'lodash-es/extend'; +import _groupBy from 'lodash-es/groupBy'; + import { t } from '../util/locale'; -import { modeDrawLine } from '../modes/index'; -import { behaviorOperation } from '../behavior/index'; +import { modeDrawLine } from '../modes'; +import { behaviorOperation } from '../behavior'; export function operationContinue(selectedIDs, context) { var graph = context.graph(), entities = selectedIDs.map(function(id) { return graph.entity(id); }), - geometries = _.extend({ line: [], vertex: [] }, - _.groupBy(entities, function(entity) { return entity.geometry(graph); })), + geometries = _extend({ line: [], vertex: [] }, + _groupBy(entities, function(entity) { return entity.geometry(graph); })), vertex = geometries.vertex[0]; diff --git a/modules/operations/delete.js b/modules/operations/delete.js index af4aad973..4eb4e2d47 100644 --- a/modules/operations/delete.js +++ b/modules/operations/delete.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import _some from 'lodash-es/some'; + import { t } from '../util/locale'; import { actionDeleteMultiple } from '../actions'; import { behaviorOperation } from '../behavior'; @@ -64,11 +65,11 @@ export function operationDelete(selectedIDs, context) { var reason; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { reason = 'too_large'; - } else if (_.some(selectedIDs, context.hasHiddenConnections)) { + } else if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; - } else if (_.some(selectedIDs, protectedMember)) { + } else if (_some(selectedIDs, protectedMember)) { reason = 'part_of_relation'; - } else if (_.some(selectedIDs, incompleteRelation)) { + } else if (_some(selectedIDs, incompleteRelation)) { reason = 'incomplete_relation'; } return reason; diff --git a/modules/operations/disconnect.js b/modules/operations/disconnect.js index 2649f0e6f..14f84538a 100644 --- a/modules/operations/disconnect.js +++ b/modules/operations/disconnect.js @@ -1,11 +1,14 @@ -import _ from 'lodash'; +import _filter from 'lodash-es/filter'; +import _some from 'lodash-es/some'; +import _without from 'lodash-es/without'; + import { t } from '../util/locale'; import { actionDisconnect } from '../actions/index'; import { behaviorOperation } from '../behavior/index'; export function operationDisconnect(selectedIDs, context) { - var vertices = _.filter(selectedIDs, function(entityId) { + var vertices = _filter(selectedIDs, function(entityId) { return context.geometry(entityId) === 'vertex'; }); @@ -13,7 +16,7 @@ export function operationDisconnect(selectedIDs, context) { action = actionDisconnect(entityId); if (selectedIDs.length > 1) { - action.limitWays(_.without(selectedIDs, entityId)); + action.limitWays(_without(selectedIDs, entityId)); } @@ -29,7 +32,7 @@ export function operationDisconnect(selectedIDs, context) { operation.disabled = function() { var reason; - if (_.some(selectedIDs, context.hasHiddenConnections)) { + if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; } return action.disabled(context.graph()) || reason; diff --git a/modules/operations/move.js b/modules/operations/move.js index 1205562a0..fd09a2783 100644 --- a/modules/operations/move.js +++ b/modules/operations/move.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import _some from 'lodash-es/some'; + import { t } from '../util/locale'; import { behaviorOperation } from '../behavior/index'; import { geoExtent } from '../geo/index'; @@ -27,9 +28,9 @@ export function operationMove(selectedIDs, context) { var reason; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { reason = 'too_large'; - } else if (_.some(selectedIDs, context.hasHiddenConnections)) { + } else if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; - } else if (_.some(selectedIDs, incompleteRelation)) { + } else if (_some(selectedIDs, incompleteRelation)) { reason = 'incomplete_relation'; } return reason; diff --git a/modules/operations/orthogonalize.js b/modules/operations/orthogonalize.js index 50f1f685e..d4d7a6bf3 100644 --- a/modules/operations/orthogonalize.js +++ b/modules/operations/orthogonalize.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import _uniq from 'lodash-es/uniq'; + import { t } from '../util/locale'; import { actionOrthogonalize } from '../actions/index'; import { behaviorOperation } from '../behavior/index'; @@ -21,7 +22,7 @@ export function operationOrthogonalize(selectedIDs, context) { return selectedIDs.length === 1 && entity.type === 'way' && entity.isClosed() && - _.uniq(entity.nodes).length > 2; + _uniq(entity.nodes).length > 2; }; diff --git a/modules/operations/reflect.js b/modules/operations/reflect.js index 7f17e2c32..09dcd5ad0 100644 --- a/modules/operations/reflect.js +++ b/modules/operations/reflect.js @@ -1,4 +1,6 @@ -import _ from 'lodash'; +import _some from 'lodash-es/some'; +import _uniqBy from 'lodash-es/uniqBy'; + import { t } from '../util/locale'; import { actionReflect } from '../actions'; import { behaviorOperation } from '../behavior'; @@ -33,7 +35,7 @@ export function operationReflect(selectedIDs, context, axis) { operation.available = function() { var nodes = utilGetAllNodes(selectedIDs, context.graph()); - return _.uniqBy(nodes, function(n) { return n.loc; }).length >= 3; + return _uniqBy(nodes, function(n) { return n.loc; }).length >= 3; }; @@ -41,9 +43,9 @@ export function operationReflect(selectedIDs, context, axis) { var reason; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { reason = 'too_large'; - } else if (_.some(selectedIDs, context.hasHiddenConnections)) { + } else if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; - } else if (_.some(selectedIDs, incompleteRelation)) { + } else if (_some(selectedIDs, incompleteRelation)) { reason = 'incomplete_relation'; } return reason; diff --git a/modules/operations/rotate.js b/modules/operations/rotate.js index 4824db9a3..75eac55b7 100644 --- a/modules/operations/rotate.js +++ b/modules/operations/rotate.js @@ -1,4 +1,6 @@ -import _ from 'lodash'; +import _some from 'lodash-es/some'; +import _uniqBy from 'lodash-es/uniqBy'; + import { t } from '../util/locale'; import { behaviorOperation } from '../behavior'; import { geoExtent } from '../geo'; @@ -20,7 +22,7 @@ export function operationRotate(selectedIDs, context) { operation.available = function() { var nodes = utilGetAllNodes(selectedIDs, context.graph()); - return _.uniqBy(nodes, function(n) { return n.loc; }).length >= 2; + return _uniqBy(nodes, function(n) { return n.loc; }).length >= 2; }; @@ -28,9 +30,9 @@ export function operationRotate(selectedIDs, context) { var reason; if (extent.area() && extent.percentContainedIn(context.extent()) < 0.8) { reason = 'too_large'; - } else if (_.some(selectedIDs, context.hasHiddenConnections)) { + } else if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; - } else if (_.some(selectedIDs, incompleteRelation)) { + } else if (_some(selectedIDs, incompleteRelation)) { reason = 'incomplete_relation'; } return reason; diff --git a/modules/operations/split.js b/modules/operations/split.js index 0823d4879..05e8b5558 100644 --- a/modules/operations/split.js +++ b/modules/operations/split.js @@ -1,4 +1,7 @@ -import _ from 'lodash'; +import _filter from 'lodash-es/filter'; +import _some from 'lodash-es/some'; +import _without from 'lodash-es/without'; + import { t } from '../util/locale'; import { actionSplit } from '../actions/index'; import { behaviorOperation } from '../behavior/index'; @@ -6,7 +9,7 @@ import { modeSelect } from '../modes/index'; export function operationSplit(selectedIDs, context) { - var vertices = _.filter(selectedIDs, function(entityId) { + var vertices = _filter(selectedIDs, function(entityId) { return context.geometry(entityId) === 'vertex'; }); @@ -16,7 +19,7 @@ export function operationSplit(selectedIDs, context) { if (vertices.length === 1) { if (selectedIDs.length > 1) { - action.limitWays(_.without(selectedIDs, entityId)); + action.limitWays(_without(selectedIDs, entityId)); } ways = action.ways(context.graph()); } @@ -35,7 +38,7 @@ export function operationSplit(selectedIDs, context) { operation.disabled = function() { var reason; - if (_.some(selectedIDs, context.hasHiddenConnections)) { + if (_some(selectedIDs, context.hasHiddenConnections)) { reason = 'connected_to_hidden'; } return action.disabled(context.graph()) || reason; diff --git a/modules/operations/straighten.js b/modules/operations/straighten.js index 5d4f8a835..b20c5846f 100644 --- a/modules/operations/straighten.js +++ b/modules/operations/straighten.js @@ -1,4 +1,5 @@ -import _ from 'lodash'; +import _uniq from 'lodash-es/uniq'; + import { t } from '../util/locale'; import { actionStraighten } from '../actions/index'; import { behaviorOperation } from '../behavior/index'; @@ -19,7 +20,7 @@ export function operationStraighten(selectedIDs, context) { return selectedIDs.length === 1 && entity.type === 'way' && !entity.isClosed() && - _.uniq(entity.nodes).length > 2; + _uniq(entity.nodes).length > 2; };