I'm working on an app which uses events. The modules of the app execute in separate containers and I thought about using Proxy to tame the events that are fired. However, I cannot seem to be able to make dispatchEvent
accept an event that has been proxied.
The following fails:
let event = new CustomEvent('my event');
let eventProxy = new Proxy(event, {});
let eventTarget = document.createElement('div');
try {
eventTarget.dispatchEvent(eventProxy); // VM134:4 Uncaught TypeError: Failed to execute 'dispatchEvent' on 'EventTarget': parameter 1 is not of type 'Event'
} catch(error) {
console.log(error.message);
}
Anyone has any ideas how dispatchEvent
can be made to accept proxies?
new Proxy(event, {})
does not create a fully transparent replacement object. You need a lot more to handle that unfortunately. – TailpiecedispatchEvent()
accept proxied object – PerianthdispatchEvent
sincedispatchEvent
is also something from outside the membrane. It's very complicated, which is why I'd generally say using a Proxy as a generic "programmable object" is a mistake. – Tailpiece