Skip to content

Commit

Permalink
Fix widget id being unchangeable
Browse files Browse the repository at this point in the history
While not recommended, the widget id should be able to be changed. And
it definitely should not throw non-self-explanatory error messages.

Change-Id: Ic2cdbde3d201e2af52616dea1be941d61452fd52
  • Loading branch information
tbuschto committed Sep 23, 2020
1 parent be680e0 commit e517bf4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doc/api/Widget.json
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
"properties": {
"id": {
"type": "string",
"description": "A string to identify the widget by using selectors. IDs are optional. It is strongly recommended that they are unique within a page."
"description": "A string to identify the widget by using selectors. IDs are optional. It is strongly recommended that they are unique within any component."
},
"class": {
"type": "string",
Expand Down
5 changes: 4 additions & 1 deletion src/tabris/Widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ export default class Widget extends NativeObject {
set id(value) {
/** @type {string} */
const id = types.string.convert(value);
Object.defineProperty(this, '_id', {enumerable: false, writable: false, value: id});
if (id === this._id) {
return;
}
Object.defineProperty(this, '_id', {enumerable: false, writable: true, value: id});
}

get id() {
Expand Down
5 changes: 3 additions & 2 deletions test/tabris/widgets/Widget.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ describe('Widget', function() {
expect(widget.id).to.equal('foo');
});

it('gets id property from widget.id', function() {
it('can set id twice', function() {
widget.id = 'foo';
widget.id = 'bar';

expect(widget.id).to.equal('foo');
expect(widget.id).to.equal('bar');
});

it('stores class property in widget.classList', function() {
Expand Down

0 comments on commit e517bf4

Please sign in to comment.