I would like to offload as much application logic into a Web Worker as possible. That includes logic that handles events. Since event propagation happens synchronously I cannot communicate with a Web Worker in order to determine if an event should be preventDefault-ed or stopPropagation-ed.
I think a solution could be to add waitUntil
(or something similar) to MouseEvents.
anchor.addEventListener('click', ev => {
ev.waitUntil(new Promise((resolve) => {
let msg = Object.assign({}, ev);
worker.postMessage(msg);
worker.onmessage = ev => {
if(ev.data.preventPlease) {
ev.preventDefault();
}
resolve();
};
});
});