WICG / web-preferences-api

The Web Preference API aims to provide a way for sites to override the value for a given user preference (e.g. color-scheme preference) in a way that fully integrates with existing Web APIs.
https://wicg.github.io/web-preferences-api/
Other
41 stars 2 forks source link

Being Map-ish seems a little overkill #4

Closed tabatkins closed 1 year ago

tabatkins commented 1 year ago

At the moment, the suggested API shape makes the PreferenceManager vaguely Map-like - you have get()/setOverride()/clearOverride(). But Maps are useful when the key space is open-ended, and that's not the case here: we have a fixed set of override names (which can change from version to version, but are closed for any given browser version.

I suggest we just define all the overrides as attributes on PreferenceManager, so you could write like navigator.preferences.colorScheme = "dark";. Then we can remove get() and set(). We could even remove clear() if we define that they're nullable.

(getSupported() giving you the allowed values is still useful, we should keep it.)

lukewarlow commented 1 year ago

The only downside to this is it might be confusing to access the value getting null and then having to look up some other way to get the UA value?

But having said that using matchMedia as the encouraged way to actually use these values is probably fine.

tabatkins commented 1 year ago

Yeah, see #6 about how this would interact with the async nature of saving/retrieving from durable storage, so getting a null to mean just "this hasn't been overridden" seems okay to me.