New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should onscreenschange
provide useful data?
#28
Comments
oscreenschange
provide useful data?onscreenschange
provide useful data?
The reason is probably that the |
Thanks for this good feedback! In #30 I suggested adding data to the events (e.g. event.isMultiScreen and event.screens, as permitted) @jakearchibald had this solid advice (along with other API shape feedback that might yield broader outcomes resolving this issue):
|
Given the TAG recommendation against adding info to events, and the new API shape's (1) use of live objects to make updated information available when events are fired and (2) greater granularity of events (Screen[Advanced].onchange, Screens.onscreenschange, and Screens.oncurrentscreenchange), I doubt we will add info to the event objects themselves. Clients can target more specific event handlers now, cache values of attributes they care to observe, and compare cached values against updated data in respective event handlers. We're definitely open to other feedback about the ergonomics here, so please let us know if this could be improved! |
Per offline discussion, @tomayac thinks we should still consider this. "Maybe the approach here would be something like an observer (similar to MutationObserver)? On the one hand you need to observe changes to existing things, like the resolution of an already connected screen increasing, but on the other hand you also need to deal with new things entering, like a new screen being connected. I think the existing event model deals well with the former, but is less suitable for the latter. Was an observer pattern discussed in this context?" I asked what info he'd expect the events to carry and their use cases; maybe Ids of screens added/removed for Screens.screenschange? Dictionaries paralleling the pre-change Screen data or a list with names of changed properties for Screens.currentscreenchange and Screen.onchange? He said: "The more I think about it the more I am inclined to see the need for something that gives me the old state vs. the new state (maybe like a MutationRecord), so I can "calculate" the "diff" myself. As simple as a capture of getScreens() before and after the change. With an observer pattern the developer could specify what changes they are interested in, like ignore color depth changes but be informed of resolution changes. " I said "IIUC, [that] can be polyfilled by caching, and might not actually help much. We can definitely add event info later, as needed, to address more concrete requests with use cases." He replied: "+1 to tying this to concrete requests. ... we may want to hear from folks who arrange, say, multiple console windows or IDE windows and have experience with this sort of thing." |
An observer pattern is actually very compelling here. As one action may cause multiple things to happen in a series. For example, unplugging a monitor triggers:
These could get batched by the OS or fired off each as their own events. It may be better for an observer event method to stream these through rather than trying to auto-batch them together. Points 2 and 3 could even each trigger their own series of events that may not be completely uniform across OSes and situations. I don't have any concrete data on all this, just speaking from observations of having worked on Windows with multi-monitor stuff before and my Mac experience with docking to other monitors. Might be worth doing a quick investigation on how the main OSes handle this stuff concretely, then determining if they do batch events internally or if they fire off each thing as a specific occurrence. |
This is an enhancement request that may merit future consideration, but there's lingering questions about the utility and correctness of providing details with screen change events. |
Right now, a
screenschange
event doesn't convey the updated data, so you end up having to do this:Ideally the new screen constellation would be somewhere contained in
e
.The text was updated successfully, but these errors were encountered: