From 12d02e0a6bf79f7b6bf2dec5011521f7c04d6cd2 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Tue, 4 Dec 2012 16:57:52 -0500 Subject: [PATCH] Copy entity in Graph#fetch This shouldn't be necessary, but someone is modifying them in place and it's causing problems elsewhere. --- js/id/graph/graph.js | 2 +- test/spec/graph/graph.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/id/graph/graph.js b/js/id/graph/graph.js index 1410dea41..5ef7daef1 100644 --- a/js/id/graph/graph.js +++ b/js/id/graph/graph.js @@ -89,7 +89,7 @@ iD.Graph.prototype = { // Resolve the id references in a way, replacing them with actual objects. fetch: function(id) { var entity = this.entities[id], nodes = []; - if (!entity.nodes || !entity.nodes.length) return entity; + if (!entity.nodes || !entity.nodes.length) return iD.Entity(entity); // TODO: shouldn't be necessary for (var i = 0, l = entity.nodes.length; i < l; i++) { nodes[i] = this.fetch(entity.nodes[i]); } diff --git a/test/spec/graph/graph.js b/test/spec/graph/graph.js index b026a8be3..487bdd0f7 100644 --- a/test/spec/graph/graph.js +++ b/test/spec/graph/graph.js @@ -59,7 +59,7 @@ describe('Graph', 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]); + expect(graph.fetch("w1").nodes[0].id).to.equal("n1"); }); });