Use object.create for graph.entities

This commit is contained in:
Ansis Brammanis
2013-01-25 14:35:46 -05:00
parent 3105923371
commit 78993bc080
3 changed files with 11 additions and 9 deletions
+1 -1
View File
@@ -164,7 +164,7 @@ iD.Connection = function() {
}
}
for (i in g.entities) {
for (i in entities) {
if (entities[i].type === 'node') {
g.transient(entities[i], 'poi', d3.functor(false));
}
+9 -5
View File
@@ -2,12 +2,12 @@ iD.Graph = function(entities, mutable) {
if (!(this instanceof iD.Graph)) return new iD.Graph(entities, mutable);
if (_.isArray(entities)) {
this.entities = {};
this.entities = Object.create(this.original);
for (var i = 0; i < entities.length; i++) {
this.entities[entities[i].id] = entities[i];
}
} else {
this.entities = entities || {};
this.entities = _.extend(Object.create(this.original), entities);
}
this.transients = {};
@@ -21,6 +21,9 @@ iD.Graph = function(entities, mutable) {
};
iD.Graph.prototype = {
original: {},
entity: function(id) {
return this.entities[id];
},
@@ -86,9 +89,10 @@ iD.Graph.prototype = {
},
merge: function(graph) {
return this.update(function () {
_.defaults(this.entities, graph.entities);
});
for (var i in graph.entities) {
this.original[i] = graph.entities[i];
}
return this;
},
replace: function(entity) {
+1 -3
View File
@@ -31,9 +31,7 @@ iD.History = function() {
},
merge: function (graph) {
for (var i = 0; i < stack.length; i++) {
stack[i].graph = stack[i].graph.merge(graph);
}
stack[0].graph.merge(graph);
},
perform: function () {