Skip to content

Commit

Permalink
Default STATE values should be preserved when rendering web components.
Browse files Browse the repository at this point in the history
Fixes metal#305
  • Loading branch information
Robert-Frampton authored and Robert-Frampton committed Nov 21, 2017
1 parent 0b84b2e commit 11eea70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/metal-web-component/src/define_web_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions packages/metal-web-component/test/define_web_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 11eea70

Please sign in to comment.