Skip to content
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

Representing state changes as multiple distinct asynchronous events can be awkward #97

Open
marijnh opened this issue Apr 9, 2024 · 0 comments

Comments

@marijnh
Copy link

marijnh commented 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 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.

@marijnh 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant