mirror of
https://github.com/FoggedLens/iD.git
synced 2026-02-13 09:12:52 +00:00
Remove lodash includes from graph, switch parentWays/parentRels to Set
(re: #6087)
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import _difference from 'lodash-es/difference';
|
||||
import _includes from 'lodash-es/includes';
|
||||
|
||||
import { debug } from '../index';
|
||||
|
||||
@@ -65,36 +64,34 @@ coreGraph.prototype = {
|
||||
parentWays: function(entity) {
|
||||
var parents = this._parentWays[entity.id];
|
||||
var result = [];
|
||||
|
||||
if (parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
result.push(this.entity(parents[i]));
|
||||
}
|
||||
parents.forEach(function(id) {
|
||||
result.push(this.entity(id));
|
||||
}, this);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
|
||||
isPoi: function(entity) {
|
||||
var parentWays = this._parentWays[entity.id];
|
||||
return !parentWays || parentWays.length === 0;
|
||||
var parents = this._parentWays[entity.id];
|
||||
return !parents || parents.size === 0;
|
||||
},
|
||||
|
||||
|
||||
isShared: function(entity) {
|
||||
var parentWays = this._parentWays[entity.id];
|
||||
return parentWays && parentWays.length > 1;
|
||||
var parents = this._parentWays[entity.id];
|
||||
return parents && parents.size > 1;
|
||||
},
|
||||
|
||||
|
||||
parentRelations: function(entity) {
|
||||
var parents = this._parentRels[entity.id];
|
||||
var result = [];
|
||||
|
||||
if (parents) {
|
||||
for (var i = 0; i < parents.length; i++) {
|
||||
result.push(this.entity(parents[i]));
|
||||
}
|
||||
parents.forEach(function(id) {
|
||||
result.push(this.entity(id));
|
||||
}, this);
|
||||
}
|
||||
return result;
|
||||
},
|
||||
@@ -171,33 +168,26 @@ coreGraph.prototype = {
|
||||
|
||||
_updateRebased: function() {
|
||||
var base = this.base();
|
||||
var i, k, child, id, keys;
|
||||
|
||||
keys = Object.keys(this._parentWays);
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
child = keys[i];
|
||||
Object.keys(this._parentWays).forEach(function(child) {
|
||||
if (base.parentWays[child]) {
|
||||
for (k = 0; k < base.parentWays[child].length; k++) {
|
||||
id = base.parentWays[child][k];
|
||||
if (!this.entities.hasOwnProperty(id) && !_includes(this._parentWays[child], id)) {
|
||||
this._parentWays[child].push(id);
|
||||
base.parentWays[child].forEach(function(id) {
|
||||
if (!this.entities.hasOwnProperty(id)) {
|
||||
this._parentWays[child].add(id);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
keys = Object.keys(this._parentRels);
|
||||
for (i = 0; i < keys.length; i++) {
|
||||
child = keys[i];
|
||||
Object.keys(this._parentRels).forEach(function(child) {
|
||||
if (base.parentRels[child]) {
|
||||
for (k = 0; k < base.parentRels[child].length; k++) {
|
||||
id = base.parentRels[child][k];
|
||||
if (!this.entities.hasOwnProperty(id) && !_includes(this._parentRels[child], id)) {
|
||||
this._parentRels[child].push(id);
|
||||
base.parentRels[child].forEach(function(id) {
|
||||
if (!this.entities.hasOwnProperty(id)) {
|
||||
this._parentRels[child].add(id);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
}
|
||||
}
|
||||
}, this);
|
||||
|
||||
this.transients = {};
|
||||
|
||||
@@ -212,7 +202,7 @@ coreGraph.prototype = {
|
||||
parentRels = parentRels || this._parentRels;
|
||||
|
||||
var type = entity && entity.type || oldentity && oldentity.type;
|
||||
var removed, added, ways, rels, i;
|
||||
var removed, added, i;
|
||||
|
||||
if (type === 'way') { // Update parentWays
|
||||
if (oldentity && entity) {
|
||||
@@ -226,14 +216,14 @@ coreGraph.prototype = {
|
||||
added = entity.nodes;
|
||||
}
|
||||
for (i = 0; i < removed.length; i++) {
|
||||
parentWays[removed[i]] = (parentWays[removed[i]] || [])
|
||||
.filter(function(id) { return id !== oldentity.id; });
|
||||
// make a copy of prototype property, store as own property, and update..
|
||||
parentWays[removed[i]] = new Set(parentWays[removed[i]]);
|
||||
parentWays[removed[i]].delete(oldentity.id);
|
||||
}
|
||||
for (i = 0; i < added.length; i++) {
|
||||
ways = (parentWays[added[i]] || [])
|
||||
.filter(function(id) { return id !== entity.id; });
|
||||
ways.push(entity.id);
|
||||
parentWays[added[i]] = ways;
|
||||
// make a copy of prototype property, store as own property, and update..
|
||||
parentWays[added[i]] = new Set(parentWays[added[i]]);
|
||||
parentWays[added[i]].add(entity.id);
|
||||
}
|
||||
|
||||
} else if (type === 'relation') { // Update parentRels
|
||||
@@ -248,14 +238,14 @@ coreGraph.prototype = {
|
||||
added = entity.members;
|
||||
}
|
||||
for (i = 0; i < removed.length; i++) {
|
||||
parentRels[removed[i].id] = (parentRels[removed[i].id] || [])
|
||||
.filter(function(id) { return id !== oldentity.id; });
|
||||
// make a copy of prototype property, store as own property, and update..
|
||||
parentRels[removed[i].id] = new Set(parentRels[removed[i].id]);
|
||||
parentRels[removed[i].id].delete(oldentity.id);
|
||||
}
|
||||
for (i = 0; i < added.length; i++) {
|
||||
rels = (parentRels[added[i].id] || [])
|
||||
.filter(function(id) { return id !== entity.id; });
|
||||
rels.push(entity.id);
|
||||
parentRels[added[i].id] = rels;
|
||||
// make a copy of prototype property, store as own property, and update..
|
||||
parentRels[added[i].id] = new Set(parentRels[added[i].id]);
|
||||
parentRels[added[i].id].add(entity.id);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user