- From: Carlos Lopez <notifications@github.com>
- Date: Sat, 25 Apr 2020 13:40:40 -0700
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/583/619437865@github.com>
I'm currently using a polyfill for `EventTarget` in NodeJS environments. I see `Deno` will support `EventTarget` out of the box, so at least we're going to get nice usage from `EventTarget`. But, for my polyfill, I'm creating a custom "get the parent" implementation via `WeakMap` as to not pollute the the property list. ```` /** * @typedef {Object} EventDispatcherEventTargetPrivateFields * @prop {Map<string, Listener[]>} listeners * @prop {function():EventDispatcherEventTarget} getParent */ /** @type {WeakMap<any, EventDispatcherEventTargetPrivateFields>} */ export const privateEventTargetFields = new WeakMap(); export default class EventDispatcherEventTarget { constructor() { privateEventTargetFields.set(this, { listeners: new Map(), getParent: () => null, }); } /* ... */ ```` `getParent()` gets checked and called during `dispatchEvent()`, much like how browsers do it. The problem is my custom implementations has to know to set `privateEventTargetFields.get(eventTarget).getParent = callback;` The reason is I'm using a context => listener => client configuration for socket connections. Client connections themselves emit events which can be captured by the listener (TCP or WebSocket). Propagation can be stopped or it can continue bubble to the context (service that spawns the listeners). It makes sense because the application architecture is tree-like already. Unfortunately, if we decide to port to `Deno` we will not be able to the official `EventTarget` implementation because spec has no "get the parent" function and no standard as to how to pass the "get the parent" function in the constructor. -- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/whatwg/dom/issues/583#issuecomment-619437865
Received on Saturday, 25 April 2020 20:40:52 UTC