mirror of
https://github.com/excalidraw/excalidraw.git
synced 2025-05-03 10:00:07 -04:00
Debounce localstorage save (#328)
I profiled dragging and it looks like it takes ~3ms to save to localStorage a smallish scene and we're doing it twice per mousemove. Let's debounce so we don't pay that cost on every mouse move. Stole the implementation from #220 which got reverted.
This commit is contained in:
parent
c745fd4e5e
commit
3db7d69849
2 changed files with 17 additions and 2 deletions
11
src/utils.ts
11
src/utils.ts
|
@ -51,3 +51,14 @@ export function measureText(text: string, font: string) {
|
|||
|
||||
return { width, height, baseline };
|
||||
}
|
||||
|
||||
export function debounce<T extends any[]>(
|
||||
fn: (...args: T) => void,
|
||||
timeout: number
|
||||
) {
|
||||
let handle = 0;
|
||||
return (...args: T) => {
|
||||
clearTimeout(handle);
|
||||
handle = window.setTimeout(() => fn(...args), timeout);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue