Closed tabatkins closed 1 year ago
(I was certain we already had this API - a "change" event on MediaList - but it looks like we don't. We should fix that.)
Duh, of course we do, it's just in CSSOM-View for some reason: https://drafts.csswg.org/cssom-view-1/#mediaquerylist
It doesn't let you directly ask "what's the value of this MQ", but you can ask "does this MQ match this value", and you can set up several to figure out the value of any particular one. (Which is good in general - MQs aren't defined to have "a value", but rather just to match a query; a single MQ can match multiple values at once. Preference queries might be different, and could possibly be considered to have a single particular value, but I don't think we should lock them to this meaning if we don't have to.)
I think this makes perfect sense. I'll work on a revision that addresses this and your other raised issues.
For now I'll move the "Should we include a new API to get the "computed" value of a preference?" into a Question at the bottom as I'm unsure how best to address that. getSupportedData
doesn't necessarily feel right but also the ergonomics of Media Query List change isn't necessarily perfect either.
(This likely depends on #4.)
I suspect we can remove
PreferenceResult
entirely and simplify the API somewhat. Right nowPreferenceResult
does three separate things:(3) likely should be done more generally, on
MediaList
- if you want to listen for changes to an MQ, you almost certainly want those changes regardless of whether they come from an override or the user's pref changing. (I was certain we already had this API - a "change" event on MediaList - but it looks like we don't. We should fix that.)(2) seems like it could reasonably live in PreferenceSupportData instead. You won't often need this data, so putting it behind a method call seems just fine.
And with those changes we'd reduce PreferenceResult to just the value string, which means we could collapse it down to just a string and eliminate the interface entirely.