Closed rjfc closed 1 year ago
Actually, it doesn't need to set them in localStorage - that's something for the user or UI to do if necessary. The system still needs to work if the Storage API is disabled or the code is running in a test suite or something. The issue is more that the API doesn't have a fallback system when getting values. The get method should just be changed so that it returns the pref's default value if a value cannot be found in localStorage. Something like this
get(pref, def) {
return localStorage.getItem(pref) ?? def ?? prefDefaults[pref];
}
^ that means def
is not really necessary, but might as well have it I guess
oh and actually it should be
return globalThis.localStorage?.getItem(pref) ...
since it's possible for localStorage to not exist
The prefs/store system does not currently make use of the default values. We need to fix it so that it sets prefs to their default values in localStorage if they haven't been set yet.