diff --git a/static/framework.js b/static/framework.js index 7754428..c627b6c 100644 --- a/static/framework.js +++ b/static/framework.js @@ -21,10 +21,19 @@ export function listen(...listenerSpecs) { export function debounce(time, fn) { let timeout = null; + let queued = null; return (...args) => { if (timeout == null) { fn(...args); - timeout = setTimeout(() => (timeout = null), time); + timeout = setTimeout(() => { + timeout = null; + if (queued != null) { + fn(...queued); + queued = null; + } + }, time); + } else { + queued = args; } }; } diff --git a/static/index.js b/static/index.js index 0045a00..9a82474 100644 --- a/static/index.js +++ b/static/index.js @@ -32,6 +32,7 @@ function updateUrl(session, viewport) { url.hash = `${session.wallId}&x=${Math.floor(viewport.panX)}&y=${Math.floor(viewport.panY)}&zoom=${viewport.zoomLevel}`; history.replaceState(null, "", url); } +updateUrl = debounce(500, updateUrl); function readUrl(urlString) { let url = new URL(urlString);