Skip to content

Commit

Permalink
add timer to event handler so we can check whether it was attached du…
Browse files Browse the repository at this point in the history
…ring the current propagation
  • Loading branch information
JoviDeCroock committed Sep 3, 2023
1 parent 7a3706a commit 16e32f4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/diff/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
}
// Benchmark for comparison: https://esbench.com/bench/574c954bdb965b9a00965ac6
else if (name[0] === 'o' && name[1] === 'n') {
useCapture = name !== (name = name.replace(/(PointerCapture)$|Capture$/, '$1'));
useCapture =
name !== (name = name.replace(/(PointerCapture)$|Capture$/, '$1'));

// Infer correct casing for DOM built-in events:
if (name.toLowerCase() in dom) name = name.toLowerCase().slice(2);
Expand All @@ -94,8 +95,11 @@ export function setProperty(dom, name, value, oldValue, isSvg) {

if (value) {
if (!oldValue) {
value._attached = Date.now();
const handler = useCapture ? eventProxyCapture : eventProxy;
dom.addEventListener(name, handler, useCapture);
} else {
value._attached = oldValue._attached;
}
} else {
const handler = useCapture ? eventProxyCapture : eventProxy;
Expand Down Expand Up @@ -151,7 +155,13 @@ export function setProperty(dom, name, value, oldValue, isSvg) {
* @private
*/
function eventProxy(e) {
return this._listeners[e.type + false](options.event ? options.event(e) : e);
const eventHandler = this._listeners[e.type + false];
if (!e._dispatched) {
e._dispatched = Date.now();
} else if (e._dispatched <= eventHandler._attached) {
return;
}
return eventHandler(options.event ? options.event(e) : e);
}

function eventProxyCapture(e) {
Expand Down

0 comments on commit 16e32f4

Please sign in to comment.