Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default STATE values should be preserved when rendering web components. Fixes #305 #309

Merged
merged 3 commits into from
Nov 22, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/metal-component/test/Component.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,13 +213,13 @@ describe('Component', function() {
assert.strictEqual(1, comp.disposed.callCount);
});

it('should emit "disposed" event when component is disposed', function () {
var listener = sinon.stub();
it('should emit "disposed" event when component is disposed', function() {
let listener = sinon.stub();

comp = new Component({
events: {
disposed: listener
}
disposed: listener,
},
});

assert.strictEqual(0, listener.callCount);
Expand Down
8 changes: 6 additions & 2 deletions packages/metal-web-component/src/define_web_component.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ export function defineWebComponent(tagName, Ctor) {
});
}

let opts = {};
const opts = {};
for (let i = 0, l = observedAttributes.length; i < l; i++) {
opts[observedAttributes[i]] = this.deserializeValue_(
const 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