chinedufn / percy

Build frontend browser apps with Rust + WebAssembly. Supports server side rendering.
https://chinedufn.github.io/percy/
Apache License 2.0
2.25k stars 84 forks source link

Implement more robust events system #157

Closed chinedufn closed 2 years ago

chinedufn commented 2 years ago

Before this commit there were a number of situations where events would not behave as expected, or just be flat out broken.

This commit solidifies the event handling system.

We now support both event delegation and as well attaching events directly onto DOM nodes.

This is handled transparency to the user, based on the event.


Before thie commit, when patching an element that has events over an element that did not have events, the new events would be ignored.

This commit ensures that we always update the events in the EventsByNodeIdx type when we are patching a node.


We also introduce the concept of event delegation, where we can have a single event handler to handle all occurrences of a type of event.

For example, we might have a single onclick handler attached to the DomUpdater's mount point that then calls the correct callback by looking it up in the EventsByNodeIdx.

Over time we'll gain more insight into on which events should be delegated vs. which events should be attached to DOM nodes.