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

Commit f60b243

Browse files
committed
Merge pull request #9918 from adobe/pflynn/robust-events
New, more robust event-dispatching system
2 parents da99471 + 110b532 commit f60b243

113 files changed

Lines changed: 1684 additions & 880 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/LiveDevelopment/Agents/CSSAgent.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ define(function CSSAgent(require, exports, module) {
3939

4040
var _ = require("thirdparty/lodash");
4141

42-
var Inspector = require("LiveDevelopment/Inspector/Inspector");
42+
var Inspector = require("LiveDevelopment/Inspector/Inspector"),
43+
EventDispatcher = require("utils/EventDispatcher");
4344

4445
/**
4546
* Stylesheet details
@@ -147,7 +148,7 @@ define(function CSSAgent(require, exports, module) {
147148
_styleSheetDetails[styleSheetId] = res.header;
148149
_styleSheetDetails[styleSheetId].canonicalizedURL = url; // canonicalized URL
149150

150-
$(exports).triggerHandler("styleSheetAdded", [url, res.header]);
151+
exports.trigger("styleSheetAdded", url, res.header);
151152
}
152153

153154
/**
@@ -160,7 +161,7 @@ define(function CSSAgent(require, exports, module) {
160161

161162
delete _styleSheetDetails[res.styleSheetId];
162163

163-
$(exports).triggerHandler("styleSheetRemoved", [header.canonicalizedURL, header]);
164+
exports.trigger("styleSheetRemoved", header.canonicalizedURL, header);
164165
}
165166

166167
/**
@@ -183,7 +184,7 @@ define(function CSSAgent(require, exports, module) {
183184
// If we have user agent string, and Chrome is >= 34, then don't use getAllStyleSheets
184185
if (uaMatch && parseInt(uaMatch[1], 10) >= 34) {
185186
_getAllStyleSheetsNotFound = true;
186-
$(Inspector.Page).off("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
187+
Inspector.Page.off("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
187188
return;
188189
}
189190
}
@@ -199,7 +200,7 @@ define(function CSSAgent(require, exports, module) {
199200
}).fail(function (err) {
200201
// Disable getAllStyleSheets if the first call fails
201202
_getAllStyleSheetsNotFound = (err.code === -32601);
202-
$(Inspector.Page).off("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
203+
Inspector.Page.off("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
203204
});
204205
}
205206

@@ -210,21 +211,24 @@ define(function CSSAgent(require, exports, module) {
210211

211212
/** Initialize the agent */
212213
function load() {
213-
$(Inspector.Page).on("frameNavigated.CSSAgent", _onFrameNavigated);
214-
$(Inspector.CSS).on("styleSheetAdded.CSSAgent", _styleSheetAdded);
215-
$(Inspector.CSS).on("styleSheetRemoved.CSSAgent", _styleSheetRemoved);
214+
Inspector.Page.on("frameNavigated.CSSAgent", _onFrameNavigated);
215+
Inspector.CSS.on("styleSheetAdded.CSSAgent", _styleSheetAdded);
216+
Inspector.CSS.on("styleSheetRemoved.CSSAgent", _styleSheetRemoved);
216217

217218
// getAllStyleSheets was deleted beginning with Chrome 34
218219
if (!_getAllStyleSheetsNotFound) {
219-
$(Inspector.Page).on("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
220+
Inspector.Page.on("frameStoppedLoading.CSSAgent", _onFrameStoppedLoading);
220221
}
221222
}
222223

223224
/** Clean up */
224225
function unload() {
225-
$(Inspector.Page).off(".CSSAgent");
226-
$(Inspector.CSS).off(".CSSAgent");
226+
Inspector.Page.off(".CSSAgent");
227+
Inspector.CSS.off(".CSSAgent");
227228
}
229+
230+
231+
EventDispatcher.makeEventDispatcher(exports);
228232

229233
// Export public functions
230234
exports.enable = enable;

src/LiveDevelopment/Agents/ConsoleAgent.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
26-
/*global define, $ */
26+
/*global define */
2727

2828
/**
2929
* ConsoleAgent forwards all console message from the remote console to the
@@ -85,15 +85,15 @@ define(function ConsoleAgent(require, exports, module) {
8585

8686
/** Initialize the agent */
8787
function load() {
88-
$(Inspector.Console)
88+
Inspector.Console
8989
.on("messageAdded.ConsoleAgent", _onMessageAdded)
9090
.on("messageRepeatCountUpdated.ConsoleAgent", _onMessageRepeatCountUpdated)
9191
.on("messagesCleared.ConsoleAgent", _onMessagesCleared);
9292
}
9393

9494
/** Clean up */
9595
function unload() {
96-
$(Inspector.Console).off(".ConsoleAgent");
96+
Inspector.Console.off(".ConsoleAgent");
9797
}
9898

9999
// Export public functions

src/LiveDevelopment/Agents/DOMAgent.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,11 @@
3838
define(function DOMAgent(require, exports, module) {
3939
"use strict";
4040

41-
var $exports = $(exports);
42-
43-
var Inspector = require("LiveDevelopment/Inspector/Inspector");
44-
var EditAgent = require("LiveDevelopment/Agents/EditAgent");
45-
var DOMNode = require("LiveDevelopment/Agents/DOMNode");
46-
var DOMHelpers = require("LiveDevelopment/Agents/DOMHelpers");
41+
var Inspector = require("LiveDevelopment/Inspector/Inspector"),
42+
EventDispatcher = require("utils/EventDispatcher"),
43+
EditAgent = require("LiveDevelopment/Agents/EditAgent"),
44+
DOMNode = require("LiveDevelopment/Agents/DOMNode"),
45+
DOMHelpers = require("LiveDevelopment/Agents/DOMHelpers");
4746

4847
var _load; // {$.Deferred} load promise
4948
var _idToNode; // {nodeId -> node}
@@ -189,7 +188,7 @@ define(function DOMAgent(require, exports, module) {
189188
function _onLoadEventFired(event, res) {
190189
// res = {timestamp}
191190
Inspector.DOM.getDocument(function onGetDocument(res) {
192-
$exports.triggerHandler("getDocument", res);
191+
exports.trigger("getDocument", res);
193192
// res = {root}
194193
_idToNode = {};
195194
_pendingRequests = 0;
@@ -294,10 +293,10 @@ define(function DOMAgent(require, exports, module) {
294293
/** Initialize the agent */
295294
function load() {
296295
_load = new $.Deferred();
297-
$(Inspector.Page)
296+
Inspector.Page
298297
.on("frameNavigated.DOMAgent", _onFrameNavigated)
299298
.on("loadEventFired.DOMAgent", _onLoadEventFired);
300-
$(Inspector.DOM)
299+
Inspector.DOM
301300
.on("documentUpdated.DOMAgent", _onDocumentUpdated)
302301
.on("setChildNodes.DOMAgent", _onSetChildNodes)
303302
.on("childNodeCountUpdated.DOMAgent", _onChildNodeCountUpdated)
@@ -308,9 +307,12 @@ define(function DOMAgent(require, exports, module) {
308307

309308
/** Clean up */
310309
function unload() {
311-
$(Inspector.Page).off(".DOMAgent");
312-
$(Inspector.DOM).off(".DOMAgent");
310+
Inspector.Page.off(".DOMAgent");
311+
Inspector.DOM.off(".DOMAgent");
313312
}
313+
314+
315+
EventDispatcher.makeEventDispatcher(exports);
314316

315317
// Export private functions
316318
exports.nodeBeforeLocation = nodeBeforeLocation;

src/LiveDevelopment/Agents/EditAgent.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
26-
/*global define, $ */
26+
/*global define */
2727

2828
/**
2929
* EditAgent propagates changes from the in-document editor to the source
@@ -105,7 +105,7 @@ define(function EditAgent(require, exports, module) {
105105

106106
// detach from DOM change events
107107
if (res.value === "0") {
108-
$(Inspector.DOM).off(".EditAgent");
108+
Inspector.DOM.off(".EditAgent");
109109
return;
110110
}
111111

@@ -118,17 +118,17 @@ define(function EditAgent(require, exports, module) {
118118
_editedNode = node;
119119

120120
// attach to character data modified events
121-
$(Inspector.DOM).on("characterDataModified.EditAgent", _onCharacterDataModified);
121+
Inspector.DOM.on("characterDataModified.EditAgent", _onCharacterDataModified);
122122
}
123123

124124
/** Initialize the agent */
125125
function load() {
126-
$(RemoteAgent).on("edit.EditAgent", _onRemoteEdit);
126+
RemoteAgent.on("edit.EditAgent", _onRemoteEdit);
127127
}
128128

129129
/** Initialize the agent */
130130
function unload() {
131-
$(RemoteAgent).off(".EditAgent");
131+
RemoteAgent.off(".EditAgent");
132132
}
133133

134134
// Export public functions

src/LiveDevelopment/Agents/GotoAgent.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,14 @@ define(function GotoAgent(require, exports, module) {
202202

203203
/** Initialize the agent */
204204
function load() {
205-
$(RemoteAgent)
205+
RemoteAgent
206206
.on("showgoto.GotoAgent", _onRemoteShowGoto)
207207
.on("goto.GotoAgent", _onRemoteGoto);
208208
}
209209

210210
/** Initialize the agent */
211211
function unload() {
212-
$(RemoteAgent).off(".GotoAgent");
212+
RemoteAgent.off(".GotoAgent");
213213
}
214214

215215
// Export public functions

src/LiveDevelopment/Agents/HighlightAgent.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
26-
/*global define, $ */
26+
/*global define */
2727

2828
/**
2929
* HighlightAgent dispatches events for highlight requests from in-browser
@@ -35,6 +35,7 @@ define(function HighlightAgent(require, exports, module) {
3535
"use strict";
3636

3737
var DOMAgent = require("LiveDevelopment/Agents/DOMAgent"),
38+
EventDispatcher = require("utils/EventDispatcher"),
3839
Inspector = require("LiveDevelopment/Inspector/Inspector"),
3940
LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
4041
RemoteAgent = require("LiveDevelopment/Agents/RemoteAgent"),
@@ -48,7 +49,7 @@ define(function HighlightAgent(require, exports, module) {
4849
if (res.value === "1") {
4950
node = DOMAgent.nodeWithId(res.nodeId);
5051
}
51-
$(exports).triggerHandler("highlight", [node]);
52+
exports.trigger("highlight", node);
5253
}
5354

5455
/** Hide in-browser highlighting */
@@ -137,16 +138,19 @@ define(function HighlightAgent(require, exports, module) {
137138
/** Initialize the agent */
138139
function load() {
139140
if (LiveDevelopment.config.experimental) {
140-
$(RemoteAgent).on("highlight.HighlightAgent", _onRemoteHighlight);
141+
RemoteAgent.on("highlight.HighlightAgent", _onRemoteHighlight);
141142
}
142143
}
143144

144145
/** Clean up */
145146
function unload() {
146147
if (LiveDevelopment.config.experimental) {
147-
$(RemoteAgent).off(".HighlightAgent");
148+
RemoteAgent.off(".HighlightAgent");
148149
}
149150
}
151+
152+
153+
EventDispatcher.makeEventDispatcher(exports);
150154

151155
// Export public functions
152156
exports.hide = hide;

src/LiveDevelopment/Agents/NetworkAgent.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424

2525
/*jslint vars: true, plusplus: true, devel: true, nomen: true, indent: 4, forin: true, maxerr: 50, regexp: true */
26-
/*global define, $ */
26+
/*global define */
2727

2828
/**
2929
* NetworkAgent tracks all resources loaded by the remote debugger. Use
@@ -88,15 +88,15 @@ define(function NetworkAgent(require, exports, module) {
8888

8989
/** Initialize the agent */
9090
function load() {
91-
$(Inspector.Page).on("frameNavigated.NetworkAgent", _onFrameNavigated);
92-
$(Inspector.Network).on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
91+
Inspector.Page.on("frameNavigated.NetworkAgent", _onFrameNavigated);
92+
Inspector.Network.on("requestWillBeSent.NetworkAgent", _onRequestWillBeSent);
9393
}
9494

9595
/** Unload the agent */
9696
function unload() {
9797
_reset();
98-
$(Inspector.Page).off(".NetworkAgent");
99-
$(Inspector.Network).off(".NetworkAgent");
98+
Inspector.Page.off(".NetworkAgent");
99+
Inspector.Network.off(".NetworkAgent");
100100
}
101101

102102
// Export public functions

src/LiveDevelopment/Agents/RemoteAgent.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@
3535
define(function RemoteAgent(require, exports, module) {
3636
"use strict";
3737

38-
var $exports = $(exports);
39-
4038
var LiveDevelopment = require("LiveDevelopment/LiveDevelopment"),
39+
EventDispatcher = require("utils/EventDispatcher"),
4140
Inspector = require("LiveDevelopment/Inspector/Inspector"),
4241
RemoteFunctions = require("text!LiveDevelopment/Agents/RemoteFunctions.js");
4342

@@ -50,7 +49,7 @@ define(function RemoteAgent(require, exports, module) {
5049
// res = {nodeId, name, value}
5150
var matches = /^data-ld-(.*)/.exec(res.name);
5251
if (matches) {
53-
$exports.triggerHandler(matches[1], res);
52+
exports.trigger(matches[1], res);
5453
}
5554
}
5655

@@ -150,20 +149,23 @@ define(function RemoteAgent(require, exports, module) {
150149
/** Initialize the agent */
151150
function load() {
152151
_load = new $.Deferred();
153-
$(Inspector.Page).on("frameNavigated.RemoteAgent", _onFrameNavigated);
154-
$(Inspector.Page).on("frameStartedLoading.RemoteAgent", _stopKeepAliveInterval);
155-
$(Inspector.DOM).on("attributeModified.RemoteAgent", _onAttributeModified);
152+
Inspector.Page.on("frameNavigated.RemoteAgent", _onFrameNavigated);
153+
Inspector.Page.on("frameStartedLoading.RemoteAgent", _stopKeepAliveInterval);
154+
Inspector.DOM.on("attributeModified.RemoteAgent", _onAttributeModified);
156155

157156
return _load.promise();
158157
}
159158

160159
/** Clean up */
161160
function unload() {
162-
$(Inspector.Page).off(".RemoteAgent");
163-
$(Inspector.DOM).off(".RemoteAgent");
161+
Inspector.Page.off(".RemoteAgent");
162+
Inspector.DOM.off(".RemoteAgent");
164163
_stopKeepAliveInterval();
165164
}
166-
165+
166+
167+
EventDispatcher.makeEventDispatcher(exports);
168+
167169
// Export public functions
168170
exports.call = call;
169171
exports.load = load;

src/LiveDevelopment/Agents/ScriptAgent.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -139,24 +139,24 @@ define(function ScriptAgent(require, exports, module) {
139139
});
140140
});
141141

142-
$(Inspector.Page).on("frameNavigated.ScriptAgent", _onFrameNavigated);
143-
$(DOMAgent).on("getDocument.ScriptAgent", _onGetDocument);
144-
$(Inspector.Debugger)
142+
Inspector.Page.on("frameNavigated.ScriptAgent", _onFrameNavigated);
143+
DOMAgent.on("getDocument.ScriptAgent", _onGetDocument);
144+
Inspector.Debugger
145145
.on("scriptParsed.ScriptAgent", _onScriptParsed)
146146
.on("scriptFailedToParse.ScriptAgent", _onScriptFailedToParse)
147147
.on("paused.ScriptAgent", _onPaused);
148-
$(Inspector.DOM).on("childNodeInserted.ScriptAgent", _onChildNodeInserted);
148+
Inspector.DOM.on("childNodeInserted.ScriptAgent", _onChildNodeInserted);
149149

150150
return $.when(_load.promise(), enableResult.promise());
151151
}
152152

153153
/** Clean up */
154154
function unload() {
155155
_reset();
156-
$(Inspector.Page).off(".ScriptAgent");
157-
$(DOMAgent).off(".ScriptAgent");
158-
$(Inspector.Debugger).off(".ScriptAgent");
159-
$(Inspector.DOM).off(".ScriptAgent");
156+
Inspector.Page.off(".ScriptAgent");
157+
DOMAgent.off(".ScriptAgent");
158+
Inspector.Debugger.off(".ScriptAgent");
159+
Inspector.DOM.off(".ScriptAgent");
160160
}
161161

162162
// Export public functions

0 commit comments

Comments
 (0)