forked from CringeStudios/gamja
store: save buffer state when user navigates away
Avoids loosing some state on page unload.
This commit is contained in:
parent
9e703698ca
commit
26cc073f41
9
store.js
9
store.js
@ -46,7 +46,14 @@ export class Buffer {
|
|||||||
let obj = this.raw.load();
|
let obj = this.raw.load();
|
||||||
this.m = new Map(Object.entries(obj || {}));
|
this.m = new Map(Object.entries(obj || {}));
|
||||||
|
|
||||||
this.save = debounce(this.save.bind(this), 500);
|
let saveImmediately = this.save.bind(this);
|
||||||
|
this.save = debounce(saveImmediately, 500);
|
||||||
|
|
||||||
|
document.addEventListener("visibilitychange", () => {
|
||||||
|
if (document.visibilityState === "hidden") {
|
||||||
|
saveImmediately();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
key(buf) {
|
key(buf) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user