store: debounce buffer store saves

This commit is contained in:
Simon Ser 2022-02-11 16:24:32 +01:00
parent 39c36e7a7b
commit f2923452c1

View file

@ -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) {