airbnb / goji-js

React ❤️ Mini Program
https://goji.js.org
MIT License
224 stars 27 forks source link

Refactor `stopPropagation` to fix #198 #202

Closed malash closed 1 year ago

malash commented 1 year ago

This PR fixed https://github.com/airbnb/goji-js/issues/198

Previously, GojiJS used e.target.dataset to detect whether an event had been stopped or not. However, this approach failed to work when crossing custom component such as Subtree or wrapped components. To improve stability, I have refactored the implementation of stopPropagation using the instance tree ( VDOM tree ).

When stopPropagation is called on an element, GojiJS marks itself and its ancestors as stopped, and they will no longer accept events with the same type and timeStamp. Throughout this process, we assume that events with the same typeandtimeStamp` are dispatched from the same source.