- From: Gavin Cannizzaro <notifications@github.com>
- Date: Fri, 23 Nov 2018 11:57:48 -0800
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/775/441310688@github.com>
To be clear, I'm talking about something like this:
```javascript
// Extend global customElements registry to allow component discovery.
(function() {
if (!customElements) return;
const registry = new Map();
const super_define = customElements.define;
Object.defineProperties(customElements, {
entries: { value: () => registry.entries() },
// Or if you prefer `[...customElements]`
[Symbol.iterator]: { value: () => registry.entries() },
define: {
value: function define(...args) {
try {
super_define.apply(this, args);
// Only register if the super call succeeds.
const [name, definition] = args;
registry.set(name, definition);
} catch (error) {
throw error;
}
}
}
});
})();
```
This works in Chrome and Firefox. Where by "works" I mean
- if you load the shim before defining any elements
- you can enumerate all successfully-defined elements using `customElements.entries()` (or just `customElements`)
- the enumeration is read-only and cannot be corrupted from the outside (although you could use access to the constructor functions to add properties to them, just as you can currently for known elements)
- everything else works exactly the same as before
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/w3c/webcomponents/issues/775#issuecomment-441310688
Received on Friday, 23 November 2018 19:58:10 UTC