Skip to content

Commit

Permalink
Address review feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Orvell committed Dec 19, 2019
1 parent f8dfaa5 commit 957c8c4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
5 changes: 5 additions & 0 deletions externs/webcomponents-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ HTMLTemplateElement.decorate = function(template){};
* @param {function(function())} cb callback
*/
CustomElementRegistry.prototype.polyfillWrapFlushCallback = function(cb){};

/**
* @param {string} cssText
*/
CSSStyleSheet.prototype.replaceSync = function(cssText) {};
5 changes: 4 additions & 1 deletion lib/legacy/class.js
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
const a = this.attributes;
for (let i=0, l=a.length; i < l; i++) {
const attr = a[i];
this.__attributeReaction(attr.name, undefined, attr.value);
this.__attributeReaction(attr.name, null, attr.value);
}
}
super.created();
Expand All @@ -309,6 +309,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
}
}

/** @override */
setAttribute(name, value) {
if (legacyNoObservedAttributes) {
const oldValue = this.getAttribute(name);
Expand All @@ -319,6 +320,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
}
}

/** @override */
removeAttribute(name) {
if (legacyNoObservedAttributes) {
const oldValue = this.getAttribute(name);
Expand Down Expand Up @@ -472,6 +474,7 @@ function GenerateClassFromInfo(info, Base, behaviors) {
}

// NOTE: Inlined for perf from version of DisableUpgradeMixin.
/** @override */
static get observedAttributes() {
return legacyNoObservedAttributes ? [] :
observedAttributesGetter.call(this).concat(DISABLED_ATTR);
Expand Down
26 changes: 25 additions & 1 deletion test/unit/legacy-noattributes.html
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,23 @@
shouldIf: Boolean,
camelCase: String,
disabled: {type: Boolean, value: 'true'}
},
attributeChanged(name, old, value) {
this.attrInfo = {name, old, value};
}
});
</script>
</dom-module>

<test-fixture id="declarative">
<template>
<x-attrs id="configured" foo="foo" bar="bar" camel-case="camelCase"></x-attrs>
<x-attrs foo="foo" bar="bar" camel-case="camelCase"></x-attrs>
</template>
</test-fixture>

<test-fixture id="one-attr">
<template>
<x-attrs foo="foo"></x-attrs>
</template>
</test-fixture>

Expand All @@ -94,6 +103,21 @@
assert.equal(el.camelCase, 'camelCase');
});

test('attributeChanged gets expected arguments', () => {
el = fixture('one-attr');
assert.deepEqual(el.attrInfo, {name: 'foo', old: null, value: 'foo'});
el.setAttribute('zot', '');
assert.deepEqual(el.attrInfo, {name: 'zot', old: null, value: ''});
el.setAttribute('zot', 'foo');
assert.deepEqual(el.attrInfo, {name: 'zot', old: '', value: 'foo'});
el.removeAttribute('zot', 'foo');
assert.deepEqual(el.attrInfo, {name: 'zot', old: 'foo', value: null});
el.setAttribute('zot', 'bar');
assert.deepEqual(el.attrInfo, {name: 'zot', old: null, value: 'bar'});
el.setAttribute('foo', 'foo2');
assert.deepEqual(el.attrInfo, {name: 'foo', old: 'foo', value: 'foo2'});
})

test('static attribute bindings', () => {
assert.equal(el.$.child1.getAttribute('bar'), 'bar');
assert.equal(el.$.child1.bar, 'bar');
Expand Down

0 comments on commit 957c8c4

Please sign in to comment.