Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Live development refactoring #1396

Merged
merged 6 commits into from
Aug 17, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/LiveDevelopment/Agents/CSSAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ define(function CSSAgent(require, exports, module) {
"use strict";

require("thirdparty/path-utils/path-utils.min");

var Inspector = require("LiveDevelopment/Inspector/Inspector");

var _load; // {$.Deferred} load promise
var _urlToStyle; // {url -> loaded} style definition

/**
* Create a canonicalized version of the given URL, stripping off query strings and hashes.
* @param {string} url the URL to canonicalize
Expand All @@ -50,7 +50,7 @@ define(function CSSAgent(require, exports, module) {
}

// WebInspector Event: Page.loadEventFired
function _onLoadEventFired(res) {
function _onLoadEventFired(event, res) {
// res = {timestamp}
_urlToStyle = {};
Inspector.CSS.getAllStyleSheets(function onGetAllStyleSheets(res) {
Expand All @@ -69,7 +69,7 @@ define(function CSSAgent(require, exports, module) {
function styleForURL(url) {
return _urlToStyle[_canonicalize(url)];
}

/** Get a list of all loaded stylesheet files by URL */
function getStylesheetURLs() {
var urls = [], url;
Expand All @@ -89,7 +89,7 @@ define(function CSSAgent(require, exports, module) {
console.assert(style, "Style Sheet for document not loaded: " + doc.url);
Inspector.CSS.setStyleSheetText(style.styleSheetId, doc.getText());
}

/** Empties a CSS style sheet given a document that has been deleted
* @param {Document} document
*/
Expand All @@ -102,13 +102,13 @@ define(function CSSAgent(require, exports, module) {
/** Initialize the agent */
function load() {
_load = new $.Deferred();
Inspector.on("Page.loadEventFired", _onLoadEventFired);
$(Inspector.Page).on("loadEventFired.CSSAgent", _onLoadEventFired);
return _load.promise();
}

/** Clean up */
function unload() {
Inspector.off("Page.loadEventFired", _onLoadEventFired);
$(Inspector.Page).off(".CSSAgent");
}

// Export public functions
Expand Down
19 changes: 9 additions & 10 deletions src/LiveDevelopment/Agents/ConsoleAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define */
/*global define, $ */

/**
* ConsoleAgent forwards all console message from the remote console to the
Expand Down Expand Up @@ -53,38 +53,37 @@ define(function ConsoleAgent(require, exports, module) {
}

// WebInspector Event: Console.messageAdded
function _onMessageAdded(res) {
function _onMessageAdded(event, res) {
// res = {message}
_lastMessage = res.message;
_log(_lastMessage);
}

// WebInspector Event: Console.messageRepeatCountUpdated
function _onMessageRepeatCountUpdated(res) {
function _onMessageRepeatCountUpdated(event, res) {
// res = {count}
if (_lastMessage) {
_log(_lastMessage);
}
}

// WebInspector Event: Console.messagesCleared
function _onMessagesCleared(res) {
function _onMessagesCleared(event, res) {
// res = {}
}

/** Initialize the agent */
function load() {
Inspector.Console.enable();
Inspector.on("Console.messageAdded", _onMessageAdded);
Inspector.on("Console.messageRepeatCountUpdated", _onMessageRepeatCountUpdated);
Inspector.on("Console.messagesCleared", _onMessagesCleared);
$(Inspector.Console)
.on("messageAdded.ConsoleAgent", _onMessageAdded)
.on("messageRepeatCountUpdated.ConsoleAgent", _onMessageRepeatCountUpdated)
.on("messagesCleared.ConsoleAgent", _onMessagesCleared);
}

/** Clean up */
function unload() {
Inspector.off("Console.messageAdded", _onMessageAdded);
Inspector.off("Console.messageRepeatCountUpdated", _onMessageRepeatCountUpdated);
Inspector.off("Console.messagesCleared", _onMessagesCleared);
$(Inspector.Console).off(".ConsoleAgent");
}

// Export public functions
Expand Down
45 changes: 22 additions & 23 deletions src/LiveDevelopment/Agents/DOMAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@
* the source document (replace [from,to] with text) call
* `applyChange(from, to, text)`.
*
* The DOMAgent triggers `DOMAgent.getDocument` on Inspector once it has loaded
* The DOMAgent triggers `getDocument` once it has loaded
* the document.
*/
define(function DOMAgent(require, exports, module) {
"use strict";

var $exports = $(exports);

var Inspector = require("LiveDevelopment/Inspector/Inspector");
var RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent");
var DOMNode = require("LiveDevelopment/Agents/DOMNode");
Expand Down Expand Up @@ -186,10 +188,10 @@ define(function DOMAgent(require, exports, module) {
}

// WebInspector Event: Page.loadEventFired
function _onLoadEventFired(res) {
function _onLoadEventFired(event, res) {
// res = {timestamp}
Inspector.DOM.getDocument(function onGetDocument(res) {
Inspector.trigger("DOMAgent.getDocument", res);
$exports.triggerHandler("getDocument", res);
// res = {root}
_idToNode = {};
_pendingRequests = 0;
Expand All @@ -198,18 +200,18 @@ define(function DOMAgent(require, exports, module) {
}

// WebInspector Event: Page.frameNavigated
function _onFrameNavigated(res) {
function _onFrameNavigated(event, res) {
// res = {frame}
exports.url = _cleanURL(res.frame.url);
}

// WebInspector Event: DOM.documentUpdated
function _onDocumentUpdated(res) {
function _onDocumentUpdated(event, res) {
// res = {}
}

// WebInspector Event: DOM.setChildNodes
function _onSetChildNodes(res) {
function _onSetChildNodes(event, res) {
// res = {parentId, nodes}
var node = nodeWithId(res.parentId);
node.setChildrenPayload(res.nodes);
Expand All @@ -219,15 +221,15 @@ define(function DOMAgent(require, exports, module) {
}

// WebInspector Event: DOM.childNodeCountUpdated
function _onChildNodeCountUpdated(res) {
function _onChildNodeCountUpdated(event, res) {
// res = {nodeId, childNodeCount}
if (res.nodeId > 0) {
Inspector.DOM.requestChildNodes(res.nodeId);
}
}

// WebInspector Event: DOM.childNodeInserted
function _onChildNodeInserted(res) {
function _onChildNodeInserted(event, res) {
// res = {parentNodeId, previousNodeId, node}
if (res.node.nodeId > 0) {
var parent = nodeWithId(res.parentNodeId);
Expand All @@ -238,7 +240,7 @@ define(function DOMAgent(require, exports, module) {
}

// WebInspector Event: DOM.childNodeRemoved
function _onChildNodeRemoved(res) {
function _onChildNodeRemoved(event, res) {
// res = {parentNodeId, nodeId}
if (res.nodeId > 0) {
var node = nodeWithId(res.nodeId);
Expand Down Expand Up @@ -286,27 +288,24 @@ define(function DOMAgent(require, exports, module) {
/** Initialize the agent */
function load() {
_load = new $.Deferred();
Inspector.on("Page.frameNavigated", _onFrameNavigated);
Inspector.on("Page.loadEventFired", _onLoadEventFired);
Inspector.on("DOM.documentUpdated", _onDocumentUpdated);
Inspector.on("DOM.setChildNodes", _onSetChildNodes);
Inspector.on("DOM.childNodeCountUpdated", _onChildNodeCountUpdated);
Inspector.on("DOM.childNodeInserted", _onChildNodeInserted);
Inspector.on("DOM.childNodeRemoved", _onChildNodeRemoved);
$(Inspector.Page)
.on("frameNavigated.DOMAgent", _onFrameNavigated)
.on("loadEventFired.DOMAgent", _onLoadEventFired);
$(Inspector.DOM)
.on("documentUpdated.DOMAgent", _onDocumentUpdated)
.on("setChildNodes.DOMAgent", _onSetChildNodes)
.on("childNodeCountUpdated.DOMAgent", _onChildNodeCountUpdated)
.on("childNodeInserted.DOMAgent", _onChildNodeInserted)
.on("childNodeRemoved.DOMAgent", _onChildNodeRemoved);
Inspector.Page.enable();
Inspector.Page.reload();
return _load.promise();
}

/** Clean up */
function unload() {
Inspector.off("Page.frameNavigated", _onFrameNavigated);
Inspector.off("Page.loadEventFired", _onLoadEventFired);
Inspector.off("DOM.documentUpdated", _onDocumentUpdated);
Inspector.off("DOM.setChildNodes", _onSetChildNodes);
Inspector.off("DOM.childNodeCountUpdated", _onChildNodeCountUpdated);
Inspector.off("DOM.childNodeInserted", _onChildNodeInserted);
Inspector.off("DOM.childNodeRemoved", _onChildNodeRemoved);
$(Inspector.Page).off(".DOMAgent");
$(Inspector.DOM).off(".DOMAgent");
}

// Export private functions
Expand Down
8 changes: 4 additions & 4 deletions src/LiveDevelopment/Agents/EditAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ define(function EditAgent(require, exports, module) {
}

// Remote Event: Go to the given source node
function _onRemoteEdit(res) {
function _onRemoteEdit(event, res) {
// res = {nodeId, name, value}
var node = DOMAgent.nodeWithId(res.nodeId);
node = node.children[0];
Expand All @@ -90,20 +90,20 @@ define(function EditAgent(require, exports, module) {
var from = codeMirror.posFromIndex(node.location + change.from);
var to = codeMirror.posFromIndex(node.location + change.to);
editor.document.replaceRange(change.text, from, to);

var newPos = codeMirror.posFromIndex(node.location + change.from + change.text.length);
editor.setCursorPos(newPos.line, newPos.ch);
}
}

/** Initialize the agent */
function load() {
Inspector.on("RemoteAgent.edit", _onRemoteEdit);
$(RemoteAgent).on("edit.EditAgent", _onRemoteEdit);
}

/** Initialize the agent */
function unload() {
Inspector.off("RemoteAgent.edit", _onRemoteEdit);
$(RemoteAgent).off(".EditAgent");
}

// Export public functions
Expand Down
12 changes: 6 additions & 6 deletions src/LiveDevelopment/Agents/GotoAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ define(function GotoAgent(require, exports, module) {
}

/** Gather options where to go to from the given source node */
function _onRemoteShowGoto(res) {
function _onRemoteShowGoto(event, res) {
// res = {nodeId, name, value}
var node = DOMAgent.nodeWithId(res.nodeId);

Expand Down Expand Up @@ -177,7 +177,7 @@ define(function GotoAgent(require, exports, module) {
}

/** Go to the given source node */
function _onRemoteGoto(res) {
function _onRemoteGoto(event, res) {
// res = {nodeId, name, value}
var location, url = res.value;
var matches = /^(.*):([^:]+)$/.exec(url);
Expand All @@ -195,14 +195,14 @@ define(function GotoAgent(require, exports, module) {

/** Initialize the agent */
function load() {
Inspector.on("RemoteAgent.showgoto", _onRemoteShowGoto);
Inspector.on("RemoteAgent.goto", _onRemoteGoto);
$(RemoteAgent)
.on("showgoto.GotoAgent", _onRemoteShowGoto)
.on("goto.GotoAgent", _onRemoteGoto);
}

/** Initialize the agent */
function unload() {
Inspector.off("RemoteAgent.showgoto", _onRemoteShowGoto);
Inspector.off("RemoteAgent.goto", _onRemoteGoto);
$(RemoteAgent).off(".GotoAgent");
}

// Export public functions
Expand Down
12 changes: 7 additions & 5 deletions src/LiveDevelopment/Agents/HighlightAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,13 @@


/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
/*global define */
/*global define, $ */

/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing jslint $ global

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

* HighlightAgent dispatches events for highlight requests from in-browser
* highlight requests, and allows highlighting nodes and rules in the browser.
*
* Trigger "highlight" when a node should be highlighted
*/
define(function HighlightAgent(require, exports, module) {
"use strict";
Expand All @@ -39,12 +41,12 @@ define(function HighlightAgent(require, exports, module) {
var _highlight; // active highlight

// Remote Event: Highlight
function _onRemoteHighlight(res) {
function _onRemoteHighlight(event, res) {
var node;
if (res.value === "1") {
node = DOMAgent.nodeWithId(res.nodeId);
}
Inspector.trigger("HighlightAgent.highlight", node);
$(exports).triggerHandler("highlight", node);
}

/** Hide in-browser highlighting */
Expand Down Expand Up @@ -103,12 +105,12 @@ define(function HighlightAgent(require, exports, module) {
/** Initialize the agent */
function load() {
_highlight = {};
Inspector.on("RemoteAgent.highlight", _onRemoteHighlight);
$(RemoteAgent).on("highlight.HighlightAgent", _onRemoteHighlight);
}

/** Clean up */
function unload() {
Inspector.off("RemoteAgent.highlight", _onRemoteHighlight);
$(RemoteAgent).off(".HighlightAgent");
}

// Export public functions
Expand Down
6 changes: 3 additions & 3 deletions src/LiveDevelopment/Agents/NetworkAgent.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ define(function NetworkAgent(require, exports, module) {
}

// WebInspector Event: Network.requestWillBeSent
function _onRequestWillBeSent(res) {
function _onRequestWillBeSent(event, res) {
// res = {requestId, frameId, loaderId, documentURL, request, timestamp, initiator, stackTrace, redirectResponse}
var url = _urlWithoutQueryString(res.request.url);
_urlRequested[url] = true;
Expand All @@ -65,12 +65,12 @@ define(function NetworkAgent(require, exports, module) {
function load() {
_urlRequested = {};
Inspector.Network.enable();
Inspector.on("Network.requestWillBeSent", _onRequestWillBeSent);
$(Inspector.Network).on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
}

/** Unload the agent */
function unload() {
Inspector.off("Network.requestWillBeSent", _onRequestWillBeSent);
$(Inspector.Network).off(".NetworkAgent");
}

// Export public functions
Expand Down
Loading