debounce updateUrl; make debounce always execute a function call after at least one is dropped
this should also fix the issue where the cursor position sometimes ends up at the wrong position after you stop moving
This commit is contained in:
parent
2a783aba71
commit
d445eb9915
2 changed files with 11 additions and 1 deletions
|
@ -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;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue