- From: Claudia Meadows <notifications@github.com>
- Date: Sun, 07 Mar 2021 03:15:26 -0800
- To: whatwg/dom <dom@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/dom/issues/958@github.com>
I'm looking at this: - `.preventDefault()` → `.defaultPrevented` - `.stopPropagation()` → `.cancelBubble` - `.stopImmediatePropagation()` → ??? I was working on a function like this, to combine attributes objects in a virtual DOM setting to allow really flexible attributes composition without much work, but as nothing like that `immediatePropagationStopped` exists (I'm not bound to that name in any way - it *is* a bit long), I instead have to rely on some property hacking (basically replacing it with a weak map + overridden method), which for anything particularly spammy, would become a major perf concern really quick. ```js function combine(...attrsObjects) { const handlers = Object.create(null) const values = Object.create(null) for (const attrs of attrsObjects) { for (const [key, value] of Object.entries(attrs)) { if (key.startsWith("on")) { (handlers[key] || (handlers[key] = [])).push(value) } else { values[key] = value } } } for (const [key, list] of Object.entries(handlers)) { values[key] = e => { for (const func of list) { if (func(e) === false) e.preventDefault() if (e.cancelBubble || e.immediatePropagationStopped) return } } } return values[key] } ``` (I'm using this in the wild, BTW. This isn't exactly academic code here.) -- 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/958
Received on Sunday, 7 March 2021 11:15:39 UTC