From 60e7698f1aaa14e12951e2c814a82104f5b378d0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 4 Dec 2012 13:30:29 -0500 Subject: [PATCH] Don't mutate entity in place --- js/id/graph/graph.js | 5 ++--- test/spec/graph/graph.js | 9 +++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index 41000fd11..1410dea41 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -88,13 +88,12 @@ iD.Graph.prototype = { // Resolve the id references in a way, replacing them with actual objects. fetch: function(id) { - var entity = iD.Entity(this.entities[id]), nodes = []; + var entity = this.entities[id], nodes = []; if (!entity.nodes || !entity.nodes.length) return entity; for (var i = 0, l = entity.nodes.length; i < l; i++) { nodes[i] = this.fetch(entity.nodes[i]); } - entity.nodes = nodes; - return entity; + return iD.Entity(entity, {nodes: nodes}); }, modifications: function() { diff --git a/test/spec/graph/graph.js b/test/spec/graph/graph.js index b90cde1f1..b026a8be3 100644 --- a/test/spec/graph/graph.js +++ b/test/spec/graph/graph.js @@ -54,6 +54,15 @@ describe('Graph', function() { }); }); + describe("#fetch", function () { + it("replaces node ids with references", function () { + var node = iD.Node({id: "n1"}), + way = iD.Way({id: "w1", nodes: ["n1"]}), + graph = iD.Graph({n1: node, w1: way}); + expect(graph.fetch("w1").nodes).to.eql([node]); + }); + }); + describe("#modifications", function () { it("filters entities by modified", function () { var a = {id: 'a', modified: function () { return true; }},