pad_cookie: Re-read prefs cookie on every call to `getPref()`

This makes it easier to write tests that clear the prefs cookie.
pull/4987/head
Richard Hansen 2021-03-25 23:59:36 -04:00 committed by webzwo0i
parent 0df41a9a78
commit 202d65d2bb
1 changed files with 7 additions and 7 deletions

View File

@ -28,8 +28,7 @@ exports.padcookie = new class {
delete prefs.userId;
delete prefs.name;
delete prefs.colorId;
this.prefs_ = prefs;
this.savePrefs_();
this.writePrefs_(prefs);
// Re-read the saved cookie to test if cookies are enabled.
if (this.readPrefs_() == null) {
$.gritter.add({
@ -51,16 +50,17 @@ exports.padcookie = new class {
}
}
savePrefs_() {
Cookies.set(this.cookieName_, JSON.stringify(this.prefs_), {expires: 365 * 100});
writePrefs_(prefs) {
Cookies.set(this.cookieName_, JSON.stringify(prefs), {expires: 365 * 100});
}
getPref(prefName) {
return this.prefs_[prefName];
return this.readPrefs_()[prefName];
}
setPref(prefName, value) {
this.prefs_[prefName] = value;
this.savePrefs_();
const prefs = this.readPrefs_();
prefs[prefName] = value;
this.writePrefs_(prefs);
}
}();