Skip to content

Commit 84f8077

Browse files
author
p01
committed
Fixed infinite search-createView loop and cleaned up the throttling
1 parent 6ca49e4 commit 84f8077

File tree

1 file changed

+35
-23
lines changed

1 file changed

+35
-23
lines changed

src/resource-manager/resource_tree_view.js

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
1919
ui_strings.S_HTTP_LABEL_FILTER_OTHER
2020
];
2121

22+
this._next_render_time = 0;
2223
this._resource_inspector = resource_inspector;
2324
this.required_services = ["resource-manager", "document-manager"];
2425

@@ -27,10 +28,31 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
2728
return GROUP_ORDER;
2829
};
2930

30-
// throttle the update
31-
this.update = this.update.bind(this).throttle(THROTTLE_DELAY);
31+
this.instant_update = function()
32+
{
33+
// Reset the _next_render_time to force an immediate render
34+
this._next_render_time = 0;
35+
this.update();
36+
};
37+
38+
this.update_bound = this.update.bind(this);
3239

3340
this.createView = function(container)
41+
{
42+
var now = Date.now();
43+
if (now >= this._next_render_time)
44+
{
45+
if (this._bounced_update)
46+
this._bounced_update = clearTimeout(this._bounced_update);
47+
48+
this._render_view(container);
49+
this._next_render_time = now + THROTTLE_DELAY;
50+
}
51+
else if (!this._bounced_update)
52+
this._bounced_update = setTimeout(this.update_bound, THROTTLE_DELAY);
53+
};
54+
55+
this._render_view = function(container)
3456
{
3557
var tpl;
3658
var ctx = this._resource_inspector.get_resource_context();
@@ -73,11 +95,11 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
7395
target.scrollTop = scroll_top;
7496
target.scrollLeft = scroll_left;
7597
}
76-
};
98+
};
7799

78100
this.ondestroy = function(container)
79101
{
80-
delete this.tpl_JSON;
102+
this.tpl_JSON = null;
81103
};
82104

83105
this.create_disabled_view = function(container)
@@ -90,11 +112,11 @@ cls.ResourceTreeView = function(id, name, container_class, html, default_handler
90112
this.id = id;
91113

92114
var messages = window.messages;
93-
messages.add_listener("debug-context-selected", this.update);
115+
messages.add_listener("debug-context-selected", this.update_bound);
94116

95117
var doc_service = window.services["document-manager"];
96-
doc_service.add_listener("abouttoloaddocument", this.update);
97-
doc_service.add_listener("documentloaded", this.update);
118+
doc_service.add_listener("abouttoloaddocument", this.update_bound);
119+
doc_service.add_listener("documentloaded", this.update_bound);
98120

99121
ActionHandlerInterface.apply(this);
100122
this._handlers = {
@@ -137,11 +159,8 @@ cls.ResourceTreeView.create_ui_widgets = function()
137159
text_search.add_listener("onbeforesearch", (function(msg)
138160
{
139161
var view = window.views.resource_tree_view;
140-
if (view.search_term != msg.search_term)
141-
{
142-
view.search_term = msg.search_term;
143-
view.update();
144-
}
162+
view.search_term = msg.search_term;
163+
view.instant_update();
145164
}).bind(text_search));
146165

147166
window.event_handlers.input["resource-tree-text-search"] = function(event, target)
@@ -156,17 +175,10 @@ cls.ResourceTreeView.create_ui_widgets = function()
156175

157176
var on_view_created = function(msg)
158177
{
159-
if (msg.id == "resource_tree_view")
178+
if (msg.id == "resource_tree_view" && msg.container)
160179
{
161-
if (msg.container)
162-
{
163-
text_search.setContainer(msg.container);
164-
text_search.set_query_selector(".resource-tree-resource-label");
165-
text_search.setFormInput(
166-
views.resource_tree_view.getToolbarControl(msg.container, "resource-tree-text-search")
167-
);
168-
window.views.resource_tree_view.search_term = "";
169-
}
180+
text_search.setContainer(msg.container);
181+
text_search.set_query_selector(".resource-tree-resource-label");
170182
}
171183
};
172184

@@ -181,6 +193,6 @@ cls.ResourceTreeView.create_ui_widgets = function()
181193

182194
window.messages.add_listener("view-created", on_view_created);
183195
window.messages.add_listener("view-destroyed", on_view_destroyed);
184-
}
196+
};
185197

186198
cls.ResourceTreeView.prototype = ViewBase;

0 commit comments

Comments
 (0)