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
parent
0df41a9a78
commit
202d65d2bb
|
@ -28,8 +28,7 @@ exports.padcookie = new class {
|
||||||
delete prefs.userId;
|
delete prefs.userId;
|
||||||
delete prefs.name;
|
delete prefs.name;
|
||||||
delete prefs.colorId;
|
delete prefs.colorId;
|
||||||
this.prefs_ = prefs;
|
this.writePrefs_(prefs);
|
||||||
this.savePrefs_();
|
|
||||||
// Re-read the saved cookie to test if cookies are enabled.
|
// Re-read the saved cookie to test if cookies are enabled.
|
||||||
if (this.readPrefs_() == null) {
|
if (this.readPrefs_() == null) {
|
||||||
$.gritter.add({
|
$.gritter.add({
|
||||||
|
@ -51,16 +50,17 @@ exports.padcookie = new class {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
savePrefs_() {
|
writePrefs_(prefs) {
|
||||||
Cookies.set(this.cookieName_, JSON.stringify(this.prefs_), {expires: 365 * 100});
|
Cookies.set(this.cookieName_, JSON.stringify(prefs), {expires: 365 * 100});
|
||||||
}
|
}
|
||||||
|
|
||||||
getPref(prefName) {
|
getPref(prefName) {
|
||||||
return this.prefs_[prefName];
|
return this.readPrefs_()[prefName];
|
||||||
}
|
}
|
||||||
|
|
||||||
setPref(prefName, value) {
|
setPref(prefName, value) {
|
||||||
this.prefs_[prefName] = value;
|
const prefs = this.readPrefs_();
|
||||||
this.savePrefs_();
|
prefs[prefName] = value;
|
||||||
|
this.writePrefs_(prefs);
|
||||||
}
|
}
|
||||||
}();
|
}();
|
||||||
|
|
Loading…
Reference in New Issue