mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 11:39:50 +02:00
fix: save persistent data
This commit is contained in:
1 parent
30e87743fc
commit
3846cbab4a
3 files changed
+8
-9
No files matched your search
@@ -20,12 +20,17 @@ export class Varuna<Type, Arguments = void> {
|
||||
let data = initial;
|
||||
|
||||
if (this.persistence && typeof localStorage !== "undefined") {
|
||||
const instance = this;
|
||||
const dehydrated = localStorage.getItem(this.persistence);
|
||||
|
||||
if (dehydrated) {
|
||||
const rehydrated = JSON.parse(dehydrated) as unknown;
|
||||
data = merge(data, rehydrated);
|
||||
}
|
||||
|
||||
window.addEventListener("beforeunload", () => {
|
||||
localStorage.setItem(this.persistence!, JSON.stringify(instance.state));
|
||||
});
|
||||
}
|
||||
|
||||
this.initialized = true;
|
||||
|
||||
Reference in new issue
Block a user