Skip to content

Commit ea2db22

Browse files
author
p01
committed
No more ResourceManager singleton.
1 parent 617e880 commit ea2db22

File tree

4 files changed

+66
-59
lines changed

4 files changed

+66
-59
lines changed

src/build-application/build_resource_manager_1_0.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@
33
window.app.builders.ResourceManager["1.0"] = function(service)
44
{
55
var network_logger = new cls.NetworkLogger();
6+
var resource_inspector = new cls.ResourceInspector(network_logger);
7+
68
new cls.ResourceTreeView("resource_tree_view",
7-
"Tree View",
89
"",
910
"",
1011
"",
11-
network_logger);
12+
"",
13+
resource_inspector);
1214
new cls.ResourceDetailView("resource_detail_view",
13-
"Detail",
1415
"",
1516
"",
16-
network_logger);
17+
"",
18+
"",
19+
resource_inspector);
1720
cls.ResourceDetailView.create_ui_widgets();
1821
cls.ResourceTreeView.create_ui_widgets();
1922

src/resource-manager/resource_detail_view.js

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,8 @@ window.cls || (window.cls = {});
66
* @constructor
77
* @extends ViewBase
88
*/
9-
cls.ResourceDetailView = function(id, name, container_class, html, default_handler, network_logger)
9+
cls.ResourceDetailView = function(id, name, container_class, html, default_handler, resource_inspector)
1010
{
11-
if (cls.ResourceDetailView.instance)
12-
{
13-
return cls.ResourceDetailView.instance;
14-
}
15-
cls.ResourceDetailView.instance = this;
16-
17-
this._service = new cls.ResourceManagerService(this, network_logger);
18-
19-
2011
this.createView = function(container)
2112
{
2213
if (this.resource && this.resource.data)
@@ -107,7 +98,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
10798
}
10899
child = child && child.nextSibling;
109100
}
110-
}
101+
};
111102

112103
this.clear_line_highlight = function(container)
113104
{
@@ -119,7 +110,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
119110
var _ele = container.querySelector("." + HIGHLIGHTED_LINE_CLASSNAME);
120111
if (_ele)
121112
_ele.removeClass(HIGHLIGHTED_LINE_CLASSNAME);
122-
}
113+
};
123114

124115
this.go_to_line = function(container, data)
125116
{
@@ -142,7 +133,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
142133

143134
this.data = data;
144135
this.resource = resource;
145-
this._service.highlight_resource(resource.uid);
136+
this.service.highlight_resource(resource.uid);
146137
this.update();
147138

148139
return true;
@@ -156,7 +147,7 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
156147

157148
this._show_resource_by_key = function(key, data)
158149
{
159-
var service = this._service;
150+
var service = this.service;
160151
var resource = service.get_resource(key) || service.get_resource_by_url(key);
161152

162153
var url = resource ? resource.url : key;
@@ -189,10 +180,18 @@ cls.ResourceDetailView = function(id, name, container_class, html, default_handl
189180
this.update();
190181
}.bind(this);
191182

192-
var messages = window.messages;
193-
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);
183+
this._init = function(id, name, container_class, html, default_handler, resource_inspector)
184+
{
185+
this.id = id;
186+
this.service = resource_inspector;
187+
188+
var messages = window.messages;
189+
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);
190+
191+
this.init(id, name, container_class, html, default_handler);
192+
};
194193

195-
this.init(id, name, container_class, html, default_handler);
194+
this._init(id, name, container_class, html, default_handler, resource_inspector)
196195
};
197196

198197
cls.ResourceDetailView.create_ui_widgets = function()

src/resource-manager/resource_service.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,8 @@ window.cls || (window.cls = {});
55
/**
66
*
77
*/
8-
cls.ResourceManagerService = function(view, network_logger)
8+
cls.ResourceInspector = function(network_logger)
99
{
10-
if (cls.ResourceManagerService.instance)
11-
return cls.ResourceManagerService.instance;
12-
13-
cls.ResourceManagerService.instance = this;
1410

1511
var THROTTLE_DELAY = 250;
1612
var TYPE_GROUP_MAPPING =
@@ -23,7 +19,6 @@ cls.ResourceManagerService = function(view, network_logger)
2319
"*": ui_strings.S_HTTP_LABEL_FILTER_OTHER
2420
};
2521

26-
this._view = view;
2722
this._network_logger = network_logger;
2823

2924
this._handle_list_documents = function(status, msg)
@@ -56,8 +51,19 @@ cls.ResourceManagerService = function(view, network_logger)
5651
this._document_resources[document_id].push(r.uid);
5752
};
5853

54+
this.get_views = function()
55+
{
56+
if (this.tree_view == null)
57+
this.tree_view = window.views.resource_tree_view;
58+
59+
if (this.detail_view == null)
60+
this.detail_view = window.views.resource_detail_view;
61+
};
62+
5963
this._update = function(msg)
6064
{
65+
this.get_views();
66+
6167
// bounce if _suppress_updates
6268
if (this._suppress_updates_url)
6369
{
@@ -78,7 +84,7 @@ cls.ResourceManagerService = function(view, network_logger)
7884
var ctx = {};
7985

8086
// get the order of the groups of resources
81-
ctx.group_order = this._view.get_group_order();
87+
ctx.group_order = this.tree_view.get_group_order();
8288

8389
// get list of window_contexts for which we saw the main_document
8490
ctx.windowList = (this._network_logger.get_window_contexts() || []).filter(function(w) {
@@ -193,7 +199,7 @@ cls.ResourceManagerService = function(view, network_logger)
193199
this._context = null;
194200
}
195201

196-
this._view.update();
202+
this.tree_view.update();
197203
};
198204

199205
this._update_bound = this._update.bind(this);
@@ -225,7 +231,7 @@ cls.ResourceManagerService = function(view, network_logger)
225231

226232
pivotIDs.forEach(function(p) { hash[p] = collapsed; });
227233

228-
this._view.update();
234+
this.tree_view.update();
229235
}
230236
}.bind(this);
231237

@@ -240,7 +246,7 @@ cls.ResourceManagerService = function(view, network_logger)
240246

241247
var uid = parent.getAttribute("data-resource-uid");
242248
this.highlight_resource(uid);
243-
cls.ResourceDetailView.instance.show_resource(uid);
249+
this.detail_view.show_resource(uid);
244250
}.bind(this);
245251

246252
this.highlight_resource = function(uid)
@@ -276,7 +282,7 @@ cls.ResourceManagerService = function(view, network_logger)
276282
uid = list[Math.min( Math.max(0, pos + increment), list.length - 1)];
277283

278284
this.highlight_resource(uid);
279-
cls.ResourceDetailView.instance.show_resource(uid);
285+
this.detail_view.show_resource(uid);
280286
};
281287

282288
this.highlight_next_resource_bound = function()
@@ -334,7 +340,6 @@ cls.ResourceManagerService = function(view, network_logger)
334340
this._document_resources = {};
335341

336342
this._suppress_uids = {};
337-
this._view.update();
338343
};
339344

340345
this.get_resource_context = function()

src/resource-manager/resource_tree_view.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@ window.cls || (window.cls = {});
66
* @constructor
77
* @extends ViewBase
88
*/
9-
cls.ResourceTreeView = function(id, name, container_class, html, default_handler, network_logger) {
10-
if (cls.ResourceTreeView.instance)
11-
{
12-
return cls.ResourceTreeView.instance;
13-
}
14-
cls.ResourceTreeView.instance = this;
15-
9+
cls.ResourceTreeView = function(id, name, container_class, html, default_handler, resource_inspector)
10+
{
1611
// const
1712
var THROTTLE_DELAY = 250;
1813
var GROUP_ORDER = [
@@ -25,10 +20,11 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
2520
];
2621

2722
// "private"
28-
this._service = new cls.ResourceManagerService(this, network_logger);
2923
this._loading = false;
3024

3125
// public
26+
this.service = resource_inspector;
27+
3228
this.get_group_order = function()
3329
{
3430
return GROUP_ORDER;
@@ -39,8 +35,7 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
3935

4036
this.createView = function(container)
4137
{
42-
var service = this._service;
43-
var ctx = this._service.get_resource_context();
38+
var ctx = this.service.get_resource_context();
4439
var target = container.firstElementChild;
4540
var scrollTop = target?target.scrollTop:0;
4641
var scrollLeft = target?target.scrollLeft:0;
@@ -118,22 +113,28 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
118113
this.update();
119114
}.bind(this);
120115

121-
var messages = window.messages;
122-
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);
116+
this._init = function()
117+
{
118+
this.id = id;
119+
120+
var messages = window.messages;
121+
messages.add_listener("debug-context-selected", this._on_debug_context_selected_bound);
123122

124-
var doc_service = window.services["document-manager"];
125-
doc_service.add_listener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
126-
doc_service.add_listener("documentloaded", this._on_documentloaded_bound);
123+
var doc_service = window.services["document-manager"];
124+
doc_service.add_listener("abouttoloaddocument", this._on_abouttoloaddocument_bound);
125+
doc_service.add_listener("documentloaded", this._on_documentloaded_bound);
127126

128-
ActionHandlerInterface.apply(this);
129-
this._handlers = {
130-
"select-next-entry": this._service.highlight_next_resource_bound,
131-
"select-previous-entry": this._service.highlight_previous_resource_bound
127+
ActionHandlerInterface.apply(this);
128+
this._handlers = {
129+
"select-next-entry": this.service.highlight_next_resource_bound,
130+
"select-previous-entry": this.service.highlight_previous_resource_bound
131+
};
132+
ActionBroker.get_instance().register_handler(this);
133+
134+
this.init(id, name, container_class, html, default_handler);
132135
};
133-
this.id = id;
134-
ActionBroker.get_instance().register_handler(this);
135136

136-
this.init(id, name, container_class, html, default_handler);
137+
this._init(id, name, container_class, html, default_handler);
137138
};
138139

139140
cls.ResourceTreeView.create_ui_widgets = function()
@@ -183,12 +184,11 @@ cls.ResourceTreeView.create_ui_widgets = function()
183184

184185
var on_view_created = function(msg)
185186
{
186-
if (msg.id === "resource_tree_view")
187+
if (msg.id == "resource_tree_view")
187188
{
188-
var scroll_container = msg.container;
189-
if (scroll_container)
189+
if (msg.container)
190190
{
191-
text_search.setContainer(scroll_container);
191+
text_search.setContainer(msg.container);
192192
text_search.set_query_selector(".resource-tree-resource-label");
193193
text_search.setFormInput(
194194
views.resource_tree_view.getToolbarControl(msg.container, "resource-tree-text-search")

0 commit comments

Comments
 (0)