-
Notifications
You must be signed in to change notification settings - Fork 94
Implementing customized built-in elements #42
Changes from 1 commit
a7073c4
ee326ff
f0eb664
8ffa12b
555e61e
e089691
0265c2d
775b224
e6eddb5
0c82e24
4485b37
851fd1b
c8f7e69
93d812a
5e15bb8
270f834
4259dda
2a6a70d
5dce865
2feec3e
c8c6627
7233ea6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -218,7 +218,7 @@ let Deferred; | |
|
||
// 7.2: | ||
const el = document.createElement(options.extends); | ||
if (el instanceof window.HTMLUnknownElement) { | ||
if (el instanceof window['HTMLUnknownElement']) { | ||
throw new Error(`Cannot extend '${options.extends}': is not a real HTMLElement`); | ||
} | ||
|
||
|
@@ -460,7 +460,7 @@ let Deferred; | |
do { | ||
const node = /** @type {!HTMLElement} */ (walker.currentNode); | ||
if (node.getAttribute('is')) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not super familiar with this polyfill, but if it hooks element creation it's more accurate to cache 'is' at creation time. The HTML spec calls this the element's "is value" IIRC. I guess you probably need to look at attributes for parsed elements. You may want to keep those values in a side WeakMap of Element -> string. That will avoid the closure type problem you mention below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree that not looking at the Since this polyfill has been rewritten to rely on monkeypatched methods instead of mutation observers, I'll have to figure out how to get the same functionality without the MutationObserver telling me if it is a newly added node or not. |
||
node.is = node.getAttribute('is'); | ||
node['is'] = node.getAttribute('is'); | ||
} | ||
this._addElement(node, visitedNodes); | ||
} while (walker.nextNode()) | ||
|
@@ -649,12 +649,13 @@ let Deferred; | |
/** | ||
* @param {!Map<string, !CustomElementDefinition>} definitions | ||
* @param {!Node|!HTMLElement|null} node | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not know much about Closure compiler's type system, but here's my attempt. This line of code causes warnings because Closures definition for Do you need me to add types to everything? Also do you need me to fix all type warnings? If so I would appreciate help on doing so |
||
* @return {CustomElementDefinition|null} | ||
*/ | ||
function getDefinition(definitions, node) { | ||
const name = typeof node.is === 'string' ? node.is : node.tagName.toLowerCase(); | ||
const name = typeof node['is'] === 'string' ? node['is'] : node.localName; | ||
const definition = definitions.get(name); | ||
if (definition) { | ||
return definition.localName === node.localName || definition.localName === node.is ? definition : null; | ||
return definition.localName === node.localName || definition.localName === node['is'] ? definition : null; | ||
} else { | ||
return null; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FWIW I think this annotation is incorrect; you may have non-HTMLElements in a document, usually SVG.