From 987a58c5bbf55043e73e57018de6edf564e42a8a Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Wed, 24 Oct 2012 12:30:55 -0400 Subject: [PATCH] Use fast things, don't send headers so that we don't duplicate requests --- js/iD/Connection.js | 26 ++++++++++++-------------- js/iD/Controller.js | 9 --------- 2 files changed, 12 insertions(+), 23 deletions(-) diff --git a/js/iD/Connection.js b/js/iD/Connection.js index 9da3eac3a..ae57d48a8 100755 --- a/js/iD/Connection.js +++ b/js/iD/Connection.js @@ -85,14 +85,23 @@ iD.Connection = function(apiURL) { // summary: Load all data from a given URL. $.ajax({ url: url, - headers: { "X-Requested-With": null }, success: parse(callback) }); } + // Private functions to parse DOM created from XML file + function filterNodeName(n) { + return function(item) { return item.nodeName === n; }; + } + + function getAttribute(obj, name) { + return _.find(obj.attributes, filterNodeName(name)).nodeValue; + } + function parse(callback) { return function(dom) { - var nodelist = _.compact(_.map(dom.childNodes[0].childNodes, function(obj) { + for (var i = 0; i < dom.childNodes[0].childNodes.length; i++) { + var obj = dom.childNodes[0].childNodes[i]; if (obj.nodeName === 'node') { var node = new iD.Node(connection, +getAttribute(obj, 'id'), @@ -100,7 +109,6 @@ iD.Connection = function(apiURL) { +getAttribute(obj, 'lon'), getTags(obj)); assign(node); - return node; } else if (obj.nodeName === 'way') { var way = new iD.Way(connection, getAttribute(obj, 'id'), @@ -114,18 +122,8 @@ iD.Connection = function(apiURL) { getTags(obj)); assign(relation); } - })); - if (callback) { callback(nodelist); } - - // Private functions to parse DOM created from XML file - function filterNodeName(n) { - return function(item) { return item.nodeName === n; }; } - - function getAttribute(obj, name) { - return _.find(obj.attributes, filterNodeName(name)).nodeValue; - } - + if (callback) { callback(); } function getTags(obj) { return _(obj.childNodes).chain() .filter(filterNodeName('tag')) diff --git a/js/iD/Controller.js b/js/iD/Controller.js index fee9dbf15..c94e95695 100755 --- a/js/iD/Controller.js +++ b/js/iD/Controller.js @@ -6,9 +6,7 @@ iD.Controller = function() { var controller = {}, state = null; - controller.editorCache = {}; controller.undoStack = new iD.UndoStack(); - // controller.stepper = new iD.ui.StepPane(); controller.setState = function(newState) { // summary: Enter a new ControllerState, firing exitState on the old one, and enterState on the new one. @@ -19,12 +17,5 @@ iD.Controller = function() { newState.enterState(); }; - controller.entityMouseEvent = function(event, entityUI) { - // summary: Pass a MouseEvent on an EntityUI (e.g. clicking a way) to the current ControllerState. - if (!this.state) { return; } - var newState = this.state.processMouseEvent(event,entityUI); - this.setState(newState); - }; - return controller; };