fix(demos): debounce setRoot call

This commit is contained in:
Drew Rygh
2015-10-13 13:46:37 -05:00
parent 7bddb6df88
commit c9f0c08de2
2 changed files with 16 additions and 1 deletions

View File

@ -68,3 +68,18 @@ export function getPageFor(hash) {
'tabs': TabsPage
}[hash]
}
export function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};