This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 491
#551 - V1 custom elements - missing functionality #552
Closed
Closed
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f4026ca
feature: #551 add CustomElementRegistry.get() and call attributeChang…
treshugart 5d45567
chore: follow exising coding convention of not using semi-colons afte…
treshugart 883045a
chore: Fix up get() test.
treshugart f2ad8be
chore: correct constructor name
treshugart 3efe5fb
IE11 requires a third argument, even if it's null.
treshugart b123ff8
Fix issue causing tree walker to fail in IE by trying to walk nodes t…
treshugart File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -150,6 +150,12 @@ var CustomElementDefinition; | |
this._addNodes(doc.childNodes); | ||
} | ||
|
||
// http://w3c.github.io/webcomponents/spec/custom/#dom-customelementsregistry-get | ||
get(localName) { | ||
const def = this._definitions.get(localName); | ||
return def ? def.constructor : undefined; | ||
} | ||
|
||
flush() { | ||
this._handleMutations(this._observer.takeRecords()); | ||
} | ||
|
@@ -237,11 +243,21 @@ var CustomElementDefinition; | |
new (definition.constructor)(); | ||
console.assert(this._newInstance == null); | ||
} | ||
if (definition.attributeChangedCallback && definition.observedAttributes.length > 0) { | ||
|
||
var observedAttributes = definition.observedAttributes; | ||
if (definition.attributeChangedCallback && observedAttributes.length > 0) { | ||
this._attributeObserver.observe(element, { | ||
attributes: true, | ||
attributeOldValue: true, | ||
attributeFilter: definition.observedAttributes, | ||
attributeFilter: observedAttributes, | ||
}); | ||
|
||
// Trigger attributeChangedCallback for existing attributes. | ||
// http://w3c.github.io/webcomponents/spec/custom/#upgrades - part 8 | ||
observedAttributes.forEach(function (name) { | ||
if (element.hasAttribute(name)) { | ||
element.attributeChangedCallback(name, null, element.getAttribute(name)); | ||
} | ||
}); | ||
} | ||
} | ||
|
@@ -296,7 +312,7 @@ var CustomElementDefinition; | |
var rawCreateElement = doc.createElement.bind(document); | ||
doc._createElement = function(tagName, callConstructor) { | ||
var customElements = win['customElements']; | ||
var element = rawCreateElement.call(document, tagName); | ||
var element = rawCreateElement(tagName); | ||
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. It's already bound to |
||
var definition = customElements._definitions.get(tagName.toLowerCase()); | ||
if (definition) { | ||
customElements._upgradeElement(element, definition, callConstructor); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,6 +313,34 @@ suite('customElements', function() { | |
done(); | ||
}); | ||
|
||
test('customElements.get', function (done) { | ||
class XBoo extensd HTMLElement {} | ||
customElements.define('x-boo-get', XGetTest); | ||
assert.equal('gaga', customElements.get('x-get-test')); | ||
done(); | ||
}); | ||
|
||
test('attributeChangedCallback for existing observed attributes', function (done) { | ||
var changed = []; | ||
class XBoo extends HTMLElement { | ||
static observedAttributes () { | ||
return ['test1']; | ||
} | ||
attributeChangedCallback(name, oldValue, newValue) { | ||
changed.push({ name, oldValue, newValue }); | ||
} | ||
} | ||
var xboo = new XBoo(); | ||
xboo.setAttribute('test1', 'test1'); | ||
xboo.setAttribute('test2', 'test2'); | ||
customElements.flush(); | ||
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. This seemed to be how other tests were initiating an upgrade pass. I'll get the tests running and then correct this if need be. |
||
assert.equal(changed.length, 1, 'should only trigger for observed attributes'); | ||
assert.equal(changed[0].name).to.equal('test1', 'name'); | ||
assert.equal(changed[0].oldValue).to.equal(null, 'oldValue'); | ||
assert.equal(changed[0].newValue).to.equal('test1', 'newValue'); | ||
done(); | ||
}); | ||
|
||
test('document.registerElement disconnectedCallbacks in prototype', function(done) { | ||
var ready, inserted, removed; | ||
class XBoo extends HTMLElement { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Changed this to lookup the property only once since there's multiple lookups below.