mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-12-01 03:27:15 -05:00
store: debounce buffer store saves
This commit is contained in:
parent
39c36e7a7b
commit
f2923452c1
1 changed files with 13 additions and 0 deletions
13
store.js
13
store.js
|
@ -37,6 +37,17 @@ export const receipts = {
|
|||
},
|
||||
};
|
||||
|
||||
function debounce(f, delay) {
|
||||
let timeout = null;
|
||||
return (...args) => {
|
||||
clearTimeout(timeout);
|
||||
timeout = setTimeout(() => {
|
||||
timeout = null;
|
||||
f(...args);
|
||||
}, delay);
|
||||
};
|
||||
}
|
||||
|
||||
export class Buffer {
|
||||
raw = new Item("buffers");
|
||||
m = null;
|
||||
|
@ -44,6 +55,8 @@ export class Buffer {
|
|||
constructor() {
|
||||
let obj = this.raw.load();
|
||||
this.m = new Map(Object.entries(obj || {}));
|
||||
|
||||
this.save = debounce(this.save.bind(this), 500);
|
||||
}
|
||||
|
||||
key(buf) {
|
||||
|
|
Loading…
Reference in a new issue