The expectation is that when on calls
worker.addEventTarget(target) on main thread, the worker will receive the delegated target via the following handler.
// in worker
addEventListener("eventtargetadded", ({delegated_target}) => {
delegated_target.addEventListener("pointermove", onPointerMove);
});
One question that needs to be answered is what is the lifetime of delegated_target?
I think the expectation is that the developer should be responsible for calling removeEventTarget and also ensure they handle the eventtargetremoved correctly on the worker side and remove any added event listeners.
What happens when the original DOM element gets removed? Do we collect the delegated target? Do we dispatch eventtargetremoved for it? I worry without doing anything it will be easy to leak memory on the worker.
The expectation is that when on calls
worker.addEventTarget(target)
on main thread, the worker will receive the delegated target via the following handler.One question that needs to be answered is what is the lifetime of
delegated_target
? I think the expectation is that the developer should be responsible for callingremoveEventTarget
and also ensure they handle theeventtargetremoved
correctly on the worker side and remove any added event listeners.What happens when the original DOM element gets removed? Do we collect the delegated target? Do we dispatch
eventtargetremoved
for it? I worry without doing anything it will be easy to leak memory on the worker.