Skip to content

Commit

Permalink
Merge pull request #18810 from chriskrycho/backport-elementId-3-16
Browse files Browse the repository at this point in the history
[BACKPORT LTS] do not throw on stable `elementId`
  • Loading branch information
rwjblue authored Mar 11, 2020
2 parents af950d2 + e9a34d2 commit a1058c3
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,39 @@ moduleFor(
}
}

['@test elementId is stable when other values change']() {
let changingArg = 'arbitrary value';
let parentInstance;
this.registerComponent('foo-bar', {
ComponentClass: Component.extend({
init() {
this._super(...arguments);
parentInstance = this;
},
changingArg: changingArg,
}),
template: '{{quux-baz elementId="stable-id" changingArg=this.changingArg}}',
});

this.registerComponent('quux-baz', {
ComponentClass: Component.extend({}),
template: '{{changingArg}}',
});

this.render('{{foo-bar}}');
this.assertComponentElement(this.firstChild.firstChild, {
attrs: { id: 'stable-id' },
content: 'arbitrary value',
});

changingArg = 'a different value';
runTask(() => set(parentInstance, 'changingArg', changingArg));
this.assertComponentElement(this.firstChild.firstChild, {
attrs: { id: 'stable-id' },
content: changingArg,
});
}

['@test can specify template with `layoutName` property']() {
let FooBarComponent = Component.extend({
elementId: 'blahzorz',
Expand Down
6 changes: 4 additions & 2 deletions packages/@ember/-internals/views/lib/views/states/in_dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ const inDOM = assign({}, hasElement, {
get() {
return elementId;
},
set() {
throw new EmberError("Changing a view's elementId after creation is not allowed");
set(value) {
if (value !== elementId) {
throw new EmberError("Changing a view's elementId after creation is not allowed");
}
},
});
}
Expand Down

0 comments on commit a1058c3

Please sign in to comment.