You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I know this is a thing that is done all over the DOM APIs, but consider the use case that this interface is designed for: an editor that manages its own visual representation of the document (in the browser DOM). When a textupdate event comes in, it updates its document to reflect the change. It then forces a DOM layout because it needs to give the edit context the appropriate control and selection bounds. For compositions, this event is then immediately followed by a textformatupdate event, which requires another DOM update. Without dodgy tricks like delaying the response to events when we expect other events to happen (which introduces new asynchronicity and potential problems around state mismatches between the edit context and the rest of the system), this is going to waste CPU time by running multiple updates for a single editing event.
At least, I assume (hope) that the information about edits and styling coming from the IME systems comes as a single package, not a stream of asynchronous events as well.
I'm not quite sure what a good solution would look like. Systems that have a single event type for all state changes, with information about what actually happened in the event object, avoid this, but that might conflict too much with the design style of the rest of the DOM. Allowing the textupdate handler (or any code, really) to 'flush' format changes, somewhat like MutationObserver.takeRecords would help.
The text was updated successfully, but these errors were encountered:
marijnh
changed the title
Representing state changes as multiple distinct asyncronous events is awkward
Representing state changes as multiple distinct asynchronous events can be awkward
Apr 9, 2024
I know this is a thing that is done all over the DOM APIs, but consider the use case that this interface is designed for: an editor that manages its own visual representation of the document (in the browser DOM). When a
textupdate
event comes in, it updates its document to reflect the change. It then forces a DOM layout because it needs to give the edit context the appropriate control and selection bounds. For compositions, this event is then immediately followed by atextformatupdate
event, which requires another DOM update. Without dodgy tricks like delaying the response to events when we expect other events to happen (which introduces new asynchronicity and potential problems around state mismatches between the edit context and the rest of the system), this is going to waste CPU time by running multiple updates for a single editing event.At least, I assume (hope) that the information about edits and styling coming from the IME systems comes as a single package, not a stream of asynchronous events as well.
I'm not quite sure what a good solution would look like. Systems that have a single event type for all state changes, with information about what actually happened in the event object, avoid this, but that might conflict too much with the design style of the rest of the DOM. Allowing the
textupdate
handler (or any code, really) to 'flush' format changes, somewhat likeMutationObserver.takeRecords
would help.The text was updated successfully, but these errors were encountered: