feat(store): _saveDisabled latch and stronger corruption-wipe coverage
This commit is contained in:
+4
-1
@@ -11,6 +11,7 @@ export class Store {
|
||||
if (!storage) throw new Error('Store requires a storage object');
|
||||
this.storage = storage;
|
||||
this.onWarn = onWarn;
|
||||
this._saveDisabled = false;
|
||||
this.targets = this._loadJson(KEY_TARGETS, {});
|
||||
this.history = this._loadJson(KEY_HISTORY, {});
|
||||
this.prefs = this._mergePrefs(this._loadJson(KEY_PREFS, null));
|
||||
@@ -34,11 +35,13 @@ export class Store {
|
||||
}
|
||||
|
||||
_saveJson(key, value) {
|
||||
if (this._saveDisabled) return false;
|
||||
try {
|
||||
this.storage.setItem(key, JSON.stringify(value));
|
||||
return true;
|
||||
} catch (e) {
|
||||
this.onWarn(`[tat] failed to persist ${key}: ${e.message}`);
|
||||
this.onWarn(`[tat] failed to persist ${key}: ${e.message}; further saves disabled for this session`);
|
||||
this._saveDisabled = true;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user