render bouncer

This commit is contained in:
Martin/Geno 2018-07-17 23:54:11 +02:00 committed by Geno
parent af80ade82b
commit ba1045aacd
1 changed files with 19 additions and 3 deletions

View File

@ -6,15 +6,17 @@ import {singelton as notify} from './element/notify';
const router = new Navigo(null, true, '#'), const router = new Navigo(null, true, '#'),
elMain = domlib.newEl('main'), elMain = domlib.newEl('main'),
elMenu = new MenuView(); elMenu = new MenuView(),
GUI_RENDER_DEBOUNCER_TIME = 100;
export {router}; export {router};
let init = false, let init = false,
currentView = new View(); currentView = new View();
export function render () { function renderView () {
if (!document.body) { if (!document.body) {
window.setTimeout(renderView, GUI_RENDER_DEBOUNCER_TIME);
return; return;
} }
@ -26,7 +28,6 @@ export function render () {
init = true; init = true;
} }
currentView.render(); currentView.render();
notify.render(); notify.render();
@ -35,6 +36,21 @@ export function render () {
router.resolve(); router.resolve();
} }
export function render () {
let timeout = false;
function reset () {
timeout = null;
}
if (timeout) {
console('skip rendering to often');
window.clearTimeout(timeout);
}else{
renderView();
}
timeout = window.setTimeout(reset, GUI_RENDER_DEBOUNCER_TIME);
}
export function setView (toView) { export function setView (toView) {
currentView.unbind(); currentView.unbind();
currentView = toView; currentView = toView;