From 957c8c4d25ac5a4fd5607b8a0372f671b5ea6642 Mon Sep 17 00:00:00 2001 From: Steven Orvell Date: Thu, 19 Dec 2019 15:32:40 -0800 Subject: [PATCH] Address review feedback. --- externs/webcomponents-externs.js | 5 +++++ lib/legacy/class.js | 5 ++++- test/unit/legacy-noattributes.html | 26 +++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/externs/webcomponents-externs.js b/externs/webcomponents-externs.js index 1d796ded48..ae141b4a90 100644 --- a/externs/webcomponents-externs.js +++ b/externs/webcomponents-externs.js @@ -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) {}; \ No newline at end of file diff --git a/lib/legacy/class.js b/lib/legacy/class.js index a625576cdc..967e635445 100644 --- a/lib/legacy/class.js +++ b/lib/legacy/class.js @@ -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(); @@ -309,6 +309,7 @@ function GenerateClassFromInfo(info, Base, behaviors) { } } + /** @override */ setAttribute(name, value) { if (legacyNoObservedAttributes) { const oldValue = this.getAttribute(name); @@ -319,6 +320,7 @@ function GenerateClassFromInfo(info, Base, behaviors) { } } + /** @override */ removeAttribute(name) { if (legacyNoObservedAttributes) { const oldValue = this.getAttribute(name); @@ -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); diff --git a/test/unit/legacy-noattributes.html b/test/unit/legacy-noattributes.html index 1594dd735b..d07c91d5e0 100644 --- a/test/unit/legacy-noattributes.html +++ b/test/unit/legacy-noattributes.html @@ -64,6 +64,9 @@ shouldIf: Boolean, camelCase: String, disabled: {type: Boolean, value: 'true'} + }, + attributeChanged(name, old, value) { + this.attrInfo = {name, old, value}; } }); @@ -71,7 +74,13 @@ + + + + @@ -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');