From 3282802233d6dbabc6e6aa28b850034176ffa203 Mon Sep 17 00:00:00 2001 From: Jonathan Diehl Date: Thu, 26 Jul 2012 08:12:45 +0200 Subject: [PATCH 1/6] Enabled the remaining agents --- src/LiveDevelopment/LiveDevelopment.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index cc09f07a61a..df5dc59d736 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -74,13 +74,11 @@ define(function LiveDevelopment(require, exports, module) { "remote": require("LiveDevelopment/Agents/RemoteAgent"), "network": require("LiveDevelopment/Agents/NetworkAgent"), "dom": require("LiveDevelopment/Agents/DOMAgent"), - "css": require("LiveDevelopment/Agents/CSSAgent") - /* FUTURE + "css": require("LiveDevelopment/Agents/CSSAgent"), "script": require("LiveDevelopment/Agents/ScriptAgent"), "highlight": require("LiveDevelopment/Agents/HighlightAgent"), "goto": require("LiveDevelopment/Agents/GotoAgent"), "edit": require("LiveDevelopment/Agents/EditAgent") - */ }; var _htmlDocumentPath; // the path of the html file open for live development From bd8dc7dd7ffc3f8a1da5a2c438a479259b0c9fb3 Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Thu, 26 Jul 2012 13:21:28 -0700 Subject: [PATCH 2/6] provide api to enable/disable LiveDevelopment agents so that extensions can use the more experimental agents --- src/LiveDevelopment/LiveDevelopment.js | 46 +++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 5 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index df5dc59d736..ed7034d5a0f 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -81,6 +81,17 @@ define(function LiveDevelopment(require, exports, module) { "edit": require("LiveDevelopment/Agents/EditAgent") }; + // Some agents are still experimental, so we don't enable them all by default + // However, extensions can enable them by calling enableAgent() + var _enabledAgents = { + "console": true, + "remote": true, + "network": true, + "dom": true, + "css": true + }; + var _loadedAgents = []; + var _htmlDocumentPath; // the path of the html file open for live development var _liveDocument; // the document open for live editing. var _relatedDocuments; // CSS and JS documents that are used by the live HTML document @@ -219,25 +230,48 @@ define(function LiveDevelopment(require, exports, module) { /** Unload the agents */ function unloadAgents() { - var i; - for (i in agents) { + _loadedAgents.forEach(function (i) { if (agents.hasOwnProperty(i) && agents[i].unload) { agents[i].unload(); } - } + }); + _loadedAgents = []; } /** Load the agents */ function loadAgents() { var i, promises = []; - for (i in agents) { - if (agents.hasOwnProperty(i) && agents[i].load) { + for (i in _enabledAgents) { + if (_enabledAgents.hasOwnProperty(i) && agents.hasOwnProperty(i) && agents[i].load) { promises.push(agents[i].load()); + _loadedAgents.push(i); } } return promises; } + /** Enable an agent. Takes effect next time a connection is made. Does not affect + * current live development sessions. + * + * @param {string} name of agent to enable + */ + function enableAgent(name) { + if (!_enabledAgents.hasOwnProperty(name)) { + _enabledAgents[name] = true; + } + } + + /** Disable an agent. Takes effect next time a connection is made. Does not affect + * current live development sessions. + * + * @param {string} name of agent to disable + */ + function disableAgent(name) { + if (_enabledAgents.hasOwnProperty(name)) { + delete _enabledAgents[name]; + } + } + /** Update the status * @param {integer} new status */ @@ -457,6 +491,8 @@ define(function LiveDevelopment(require, exports, module) { exports.agents = agents; exports.open = open; exports.close = close; + exports.enableAgent = enableAgent; + exports.disableAgent = disableAgent; exports.getLiveDocForPath = getLiveDocForPath; exports.hideHighlight = hideHighlight; exports.init = init; From e67c7d23f191b3415e088f210ee96d7bbd5fbaa1 Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Thu, 26 Jul 2012 14:34:03 -0700 Subject: [PATCH 3/6] improve variable names and add a few comments --- src/LiveDevelopment/LiveDevelopment.js | 31 +++++++++++++------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index ed7034d5a0f..869e21a28b4 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -82,15 +82,18 @@ define(function LiveDevelopment(require, exports, module) { }; // Some agents are still experimental, so we don't enable them all by default - // However, extensions can enable them by calling enableAgent() - var _enabledAgents = { + // However, extensions can enable them by calling enableAgent(). + // This object is used as a set (thus all properties have the value 'true'). + // Property names should match property names in the 'agents' object. + var _enabledAgentNames = { "console": true, "remote": true, "network": true, "dom": true, "css": true }; - var _loadedAgents = []; + // store the names (matching property names in the 'agent' object) of agents that we've loaded + var _loadedAgentNames = []; var _htmlDocumentPath; // the path of the html file open for live development var _liveDocument; // the document open for live editing. @@ -230,21 +233,19 @@ define(function LiveDevelopment(require, exports, module) { /** Unload the agents */ function unloadAgents() { - _loadedAgents.forEach(function (i) { - if (agents.hasOwnProperty(i) && agents[i].unload) { - agents[i].unload(); - } + _loadedAgentNames.forEach(function (i) { + agents[i].unload(); }); - _loadedAgents = []; + _loadedAgentNames = []; } /** Load the agents */ function loadAgents() { var i, promises = []; - for (i in _enabledAgents) { - if (_enabledAgents.hasOwnProperty(i) && agents.hasOwnProperty(i) && agents[i].load) { + for (i in _enabledAgentNames) { + if (_enabledAgentNames.hasOwnProperty(i) && agents.hasOwnProperty(i) && agents[i].load) { promises.push(agents[i].load()); - _loadedAgents.push(i); + _loadedAgentNames.push(i); } } return promises; @@ -256,8 +257,8 @@ define(function LiveDevelopment(require, exports, module) { * @param {string} name of agent to enable */ function enableAgent(name) { - if (!_enabledAgents.hasOwnProperty(name)) { - _enabledAgents[name] = true; + if (!_enabledAgentNames.hasOwnProperty(name)) { + _enabledAgentNames[name] = true; } } @@ -267,8 +268,8 @@ define(function LiveDevelopment(require, exports, module) { * @param {string} name of agent to disable */ function disableAgent(name) { - if (_enabledAgents.hasOwnProperty(name)) { - delete _enabledAgents[name]; + if (_enabledAgentNames.hasOwnProperty(name)) { + delete _enabledAgentNames[name]; } } From 2223087376a330559e33d70beed6a0b5f793a488 Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Thu, 26 Jul 2012 14:38:19 -0700 Subject: [PATCH 4/6] changed iteration variable name --- src/LiveDevelopment/LiveDevelopment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 869e21a28b4..2e6836a2122 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -233,8 +233,8 @@ define(function LiveDevelopment(require, exports, module) { /** Unload the agents */ function unloadAgents() { - _loadedAgentNames.forEach(function (i) { - agents[i].unload(); + _loadedAgentNames.forEach(function (name) { + agents[name].unload(); }); _loadedAgentNames = []; } From 5c72190a5de4ba3e5f7a4810a031f87240eb309a Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Thu, 26 Jul 2012 14:51:33 -0700 Subject: [PATCH 5/6] improve another iteration variable name --- src/LiveDevelopment/LiveDevelopment.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index 2e6836a2122..a66adb60d35 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -241,11 +241,11 @@ define(function LiveDevelopment(require, exports, module) { /** Load the agents */ function loadAgents() { - var i, promises = []; - for (i in _enabledAgentNames) { - if (_enabledAgentNames.hasOwnProperty(i) && agents.hasOwnProperty(i) && agents[i].load) { - promises.push(agents[i].load()); - _loadedAgentNames.push(i); + var name, promises = []; + for (name in _enabledAgentNames) { + if (_enabledAgentNames.hasOwnProperty(name) && agents.hasOwnProperty(name) && agents[name].load) { + promises.push(agents[name].load()); + _loadedAgentNames.push(name); } } return promises; From 1bce0f33cd36b02b269e056b90be376da6e8e5e3 Mon Sep 17 00:00:00 2001 From: Joel Brandt Date: Thu, 26 Jul 2012 15:40:58 -0700 Subject: [PATCH 6/6] better value checking --- src/LiveDevelopment/LiveDevelopment.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/LiveDevelopment/LiveDevelopment.js b/src/LiveDevelopment/LiveDevelopment.js index a66adb60d35..b25790d4d29 100644 --- a/src/LiveDevelopment/LiveDevelopment.js +++ b/src/LiveDevelopment/LiveDevelopment.js @@ -243,7 +243,7 @@ define(function LiveDevelopment(require, exports, module) { function loadAgents() { var name, promises = []; for (name in _enabledAgentNames) { - if (_enabledAgentNames.hasOwnProperty(name) && agents.hasOwnProperty(name) && agents[name].load) { + if (_enabledAgentNames.hasOwnProperty(name) && agents[name].load) { promises.push(agents[name].load()); _loadedAgentNames.push(name); } @@ -257,7 +257,7 @@ define(function LiveDevelopment(require, exports, module) { * @param {string} name of agent to enable */ function enableAgent(name) { - if (!_enabledAgentNames.hasOwnProperty(name)) { + if (agents.hasOwnProperty(name) && !_enabledAgentNames.hasOwnProperty(name)) { _enabledAgentNames[name] = true; } }