Skip to content

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

Open
@marijnh

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions