From 11eea706398f70c88fc12b1485093c7fac164caf Mon Sep 17 00:00:00 2001 From: Robert-Frampton Date: Tue, 21 Nov 2017 14:59:47 -0800 Subject: [PATCH] Default STATE values should be preserved when rendering web components. Fixes #305 --- packages/metal-web-component/src/define_web_component.js | 6 +++++- .../metal-web-component/test/define_web_component.js | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/metal-web-component/src/define_web_component.js b/packages/metal-web-component/src/define_web_component.js index 93bf10c3..854d0a68 100644 --- a/packages/metal-web-component/src/define_web_component.js +++ b/packages/metal-web-component/src/define_web_component.js @@ -80,9 +80,13 @@ export function defineWebComponent(tagName, Ctor) { let opts = {}; for (let i = 0, l = observedAttributes.length; i < l; i++) { - opts[observedAttributes[i]] = this.deserializeValue_( + let deserializedValue = this.deserializeValue_( this.getAttribute(observedAttributes[i]) ); + + if (deserializedValue) { + opts[observedAttributes[i]] = deserializedValue; + } } this.component = new Ctor(opts, element); this.componentHasProps = hasProps; diff --git a/packages/metal-web-component/test/define_web_component.js b/packages/metal-web-component/test/define_web_component.js index b1f9dce8..8ba8783d 100644 --- a/packages/metal-web-component/test/define_web_component.js +++ b/packages/metal-web-component/test/define_web_component.js @@ -137,6 +137,15 @@ describe('Web components', function() { assert.isUndefined(title.key1); assert.equal(title.key3, 'value3'); }); + + it('should have the default state value after rendering', function() { + const tagName = createWebComponent('custom-test-element-09'); + el = document.createElement(tagName); + + document.body.appendChild(el); + + assert.equal(el.component.title, 'default title'); + }); }); describe('Define JSX component', function() {