- From: Domenic Denicola <notifications@github.com>
- Date: Thu, 03 Mar 2016 05:11:48 -0800
- To: w3c/webcomponents <webcomponents@noreply.github.com>
- Message-ID: <w3c/webcomponents/issues/369/191754665@github.com>
Upon sleeping on this I am amenable to a new alternative, which is a _mandatory_ document parameter to all custom element constructors. So: - HTMLElement takes a mandatory first argument which is the document in which it is created. - super() calls inside custom element constructors must pass that first argument. This is probably easiest accomplished by doing `constructor(...args) { super(...args); ... }`, or maybe `constructor(document, optionalSpecialStuff) { super(document); ... }` - The parser and createElement pass the relevant document as the first parameter to the custom element constructor (`new CustomElement(relevantDocument)`) - As a corollary, in general `new CustomElement()` will not work. - This should make the `new CustomElement(document)` <-> `document.createElement("custom-element")` connection more obvious. They are simply alternative syntaxes for each other. - `new CustomElement()` could be made to work by authors if they do something like `constructor() { super(window.document); }`. - But doing this is opting in to a behavior which prevents your element from being used correctly when registered on other documents. - This is forward-compatible with future expansions like passing an optional tag name (which I would still prefer to be in a dictionary). I am not OK with it defaulting to some specific document because it is ambiguous which document. We either: 1. Should make this safe for authors by ensuring a 1:1 window:custom element registration setup (e.g. by sharing or disallowing registries in non-windowed documents), so that `new CustomElement()` is unambiguous 2. Or should make this an explicit mandatory part of the API that authors need to be aware of. WDYT? (1) or (2)? --- Reply to this email directly or view it on GitHub: https://github.com/w3c/webcomponents/issues/369#issuecomment-191754665
Received on Thursday, 3 March 2016 13:12:15 UTC