Fixed linting - moved function out of loop

This commit is contained in:
J Guthrie
2019-02-24 02:19:29 +00:00
committed by Bryan Housel
parent 9d452c9ffe
commit 97dc659b0f
2 changed files with 16 additions and 10 deletions

View File

@@ -43,10 +43,10 @@ export function actionStraighten(selectedIDs, projection) {
// and need to be removed so currNode _difference calculation below works)
// i.e. ["n-1", "n-1", "n-2"] => ["n-2"]
startNodes = _filter(startNodes, function(n) {
return startNodes.indexOf(n) == startNodes.lastIndexOf(n);
return startNodes.indexOf(n) === startNodes.lastIndexOf(n);
});
endNodes = _filter(endNodes, function(n) {
return endNodes.indexOf(n) == endNodes.lastIndexOf(n);
return endNodes.indexOf(n) === endNodes.lastIndexOf(n);
});
// Choose the initial endpoint to start from
@@ -54,15 +54,20 @@ export function actionStraighten(selectedIDs, projection) {
nextWay = [];
nodes = [];
// Create nested function outside of loop to avoid "function in loop" lint error
var getNextWay = function(currNode, remainingWays) {
return _filter(remainingWays, function(way) {
return way[0] === currNode || way[way.length-1] === currNode;
})[0];
};
// Add nodes to end of nodes array, until all ways are added
while (remainingWays.length) {
nextWay = _filter(remainingWays, function(way) {
return way[0] == currNode || way[way.length-1] == currNode;
})[0];
nextWay = getNextWay(currNode, remainingWays);
remainingWays = _difference(remainingWays, [nextWay]);
if (nextWay[0] != currNode) {
if (nextWay[0] !== currNode) {
nextWay.reverse();
}
nodes = nodes.concat(nextWay);
@@ -71,7 +76,7 @@ export function actionStraighten(selectedIDs, projection) {
}
// If user selected 2 nodes to straighten between, then slice nodes array to those nodes
if (selectedNodes.length == 2) {
if (selectedNodes.length === 2) {
var startNodeIdx = nodes.indexOf(selectedNodes[0]),
endNodeIdx = nodes.indexOf(selectedNodes[1]),
sortedStartEnd = [startNodeIdx, endNodeIdx];
@@ -84,7 +89,7 @@ export function actionStraighten(selectedIDs, projection) {
}
return nodes.map(function(n) { return graph.entity(n); });
};
}
var action = function(graph, t) {
if (t === null || !isFinite(t)) t = 1;

View File

@@ -1,6 +1,7 @@
import _uniq from 'lodash-es/uniq';
import _difference from 'lodash-es/difference';
import _includes from 'lodash-es/includes';
import _filter from 'lodash-es/filter';
import { t } from '../util/locale';
import { actionStraighten } from '../actions/index';
@@ -44,10 +45,10 @@ export function operationStraighten(selectedIDs, context) {
// Remove duplicate end/startNodes (duplicate nodes cannot be at the line end)
startNodes = _filter(startNodes, function(n) {
return startNodes.indexOf(n) == startNodes.lastIndexOf(n);
return startNodes.indexOf(n) === startNodes.lastIndexOf(n);
});
endNodes = _filter(endNodes, function(n) {
return endNodes.indexOf(n) == endNodes.lastIndexOf(n);
return endNodes.indexOf(n) === endNodes.lastIndexOf(n);
});
// Return false if line is only 2 nodes long