Fix checkbox being checked by default when the value was actually `null` (#221)

Fix `debugActiveDateIntersectionObserver` checkbox being checked by default when the value was actually `null`.
Now we properly only care about explicit `'true'`, `'false'` from local storage.

Before:
```
<input id="debugActiveDateIntersectionObserver" type="checkbox" checked="null">
```

After:
```
<input id="debugActiveDateIntersectionObserver" type="checkbox">
```
This commit is contained in:
Eric Eastwood 2023-05-05 19:44:49 -05:00 committed by GitHub
parent ed3fde7845
commit bf8040f48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 7 deletions

View File

@ -14,16 +14,24 @@ class DeveloperOptionsContentViewModel extends ViewModel {
} }
loadValuesFromPersistence() { loadValuesFromPersistence() {
// Debugging is disabled by default and only enabled with the correct 'true' value
let debugActiveDateIntersectionObserver = false;
if (window.localStorage) { if (window.localStorage) {
this._debugActiveDateIntersectionObserver = JSON.parse( const debugActiveDateIntersectionObserverFromPersistence = window.localStorage.getItem(
window.localStorage.getItem(LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver) LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver
); );
this.emitChange('debugActiveDateIntersectionObserver');
if (debugActiveDateIntersectionObserverFromPersistence === 'true') {
debugActiveDateIntersectionObserver = true;
}
} else { } else {
console.warn( console.warn(
`Skipping \`${LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver}\` read from LocalStorage since LocalStorage is not available` `Skipping \`${LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver}\` read from LocalStorage since LocalStorage is not available`
); );
} }
this.toggleDebugActiveDateIntersectionObserver(debugActiveDateIntersectionObserver);
} }
get debugActiveDateIntersectionObserver() { get debugActiveDateIntersectionObserver() {
@ -32,10 +40,17 @@ class DeveloperOptionsContentViewModel extends ViewModel {
toggleDebugActiveDateIntersectionObserver(checkedValue) { toggleDebugActiveDateIntersectionObserver(checkedValue) {
this._debugActiveDateIntersectionObserver = checkedValue; this._debugActiveDateIntersectionObserver = checkedValue;
if (window.localStorage) {
window.localStorage.setItem( window.localStorage.setItem(
LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver, LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver,
this._debugActiveDateIntersectionObserver this._debugActiveDateIntersectionObserver ? 'true' : 'false'
); );
} else {
console.warn(
`Skipping \`${LOCAL_STORAGE_KEYS.debugActiveDateIntersectionObserver}\` write to LocalStorage since LocalStorage is not available`
);
}
this.emitChange('debugActiveDateIntersectionObserver'); this.emitChange('debugActiveDateIntersectionObserver');
} }