From 78993bc080b19932e96d1065f1ce4492a3404190 Mon Sep 17 00:00:00 2001 From: Ansis Brammanis Date: Fri, 25 Jan 2013 14:35:46 -0500 Subject: [PATCH] Use object.create for graph.entities --- js/id/connection.js | 2 +- js/id/graph/graph.js | 14 +++++++++----- js/id/graph/history.js | 4 +--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/js/id/connection.js b/js/id/connection.js index 326e9ebfa..10b88231e 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -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)); } diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index f5a615852..cb81b2e6c 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -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) { diff --git a/js/id/graph/history.js b/js/id/graph/history.js index c71ba0c38..f6377355f 100644 --- a/js/id/graph/history.js +++ b/js/id/graph/history.js @@ -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 () {