Skip to content
This repository has been archived by the owner on Nov 26, 2020. It is now read-only.

Commit

Permalink
small refactorings
Browse files Browse the repository at this point in the history
  • Loading branch information
codeofsumit committed Feb 15, 2019
1 parent 37edcca commit ccf5ed8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 35 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": ["airbnb-base", "prettier"],
"rules": {
"no-underscore-dangle": 0,
"import/prefer-default-export": 0,
"keyword-spacing": 0,
"no-param-reassign": 0,
"no-restricted-syntax": 0,
Expand Down
67 changes: 43 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@babel/preset-env": "^7.3.1",
"babel-loader": "^8.0.5",
"css-loader": "^0.28.11",
"cypress": "^3.1.4",
"cypress": "^3.1.5",
"eslint": "^4.19.1",
"eslint-config-airbnb-base": "^12.1.0",
"eslint-config-prettier": "^3.6.0",
Expand Down
14 changes: 4 additions & 10 deletions src/js/Edit/L.PM.Edit.Line.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import kinks from '@turf/kinks';
import get from 'lodash/get';
import Edit from './L.PM.Edit';
import Utils from '../L.PM.Utils';
import { isEmptyDeep } from '../helpers';

// Shit's getting complicated in here with Multipolygon Support. So here's a quick note about it:
// Multipolygons with holes means lots of nested, multidimensional arrays.
Expand All @@ -23,6 +24,8 @@ Edit.Line = Edit.extend({
} else {
this.disable();
}

return this.enabled();
},

enable(options) {
Expand Down Expand Up @@ -395,7 +398,7 @@ Edit.Line = Edit.extend({
// TODO: we may should remove all empty coord-rings here as well.

// if no coords are left, remove the layer
if (this.isEmptyDeep(coords)) {
if (isEmptyDeep(coords)) {
this._layer.remove();
}

Expand Down Expand Up @@ -445,15 +448,6 @@ Edit.Line = Edit.extend({
// TODO: maybe add latlng as well?
});
},
isEmptyDeep(l) {
// thanks for the function, Felix Heck
const flatten = list =>
list
.filter(x => ![null, '', undefined].includes(x))
.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);

return !flatten(l).length;
},
findDeepMarkerIndex(arr, marker) {
// thanks for the function, Felix Heck
let result;
Expand Down
9 changes: 9 additions & 0 deletions src/js/helpers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export function isEmptyDeep(l) {
// thanks for the function, Felix Heck
const flatten = list =>
list
.filter(x => ![null, '', undefined].includes(x))
.reduce((a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []);

return !flatten(l).length;
}

0 comments on commit ccf5ed8

Please sign in to comment.