Skip to content

Commit 43cee3c

Browse files
committed
Debounce devtools search
1 parent 2404353 commit 43cee3c

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

devtools/test_dashboard/devtools.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,24 @@ var searchBar = document.getElementById('mocks-search');
134134
var mocksList = document.getElementById('mocks-list');
135135
var plotArea = document.getElementById('plots');
136136

137-
searchBar.addEventListener('keyup', function(e) {
137+
searchBar.addEventListener('keyup', debounce(searchMocks, 250));
138+
139+
function debounce(func, wait, immediate) {
140+
var timeout;
141+
return function() {
142+
var context = this, args = arguments;
143+
var later = function() {
144+
timeout = null;
145+
if(!immediate) func.apply(context, args);
146+
};
147+
var callNow = immediate && !timeout;
148+
clearTimeout(timeout);
149+
timeout = setTimeout(later, wait);
150+
if(callNow) func.apply(context, args);
151+
};
152+
}
153+
154+
function searchMocks(e) {
138155

139156
// Clear results.
140157
while(mocksList.firstChild) {
@@ -162,4 +179,4 @@ searchBar.addEventListener('keyup', function(e) {
162179
var plotAreaWidth = Math.floor(window.innerWidth - listWidth);
163180
plotArea.setAttribute('style', 'width: ' + plotAreaWidth + 'px;');
164181
});
165-
});
182+
}

0 commit comments

Comments
 (0)