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 'tabs': TabsPage
}[hash] }[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);
};
};

View File

@ -26,7 +26,7 @@ class DemoApp {
this.nextPage = ActionSheetPage; this.nextPage = ActionSheetPage;
} }
let nav = this.app.getComponent('nav'); let nav = this.app.getComponent('nav');
nav.setRoot(this.nextPage); helpers.debounce(nav.setRoot(this.nextPage), 100, true);
} }
}); });
}); });