Skip to content

Commit ec2e27e

Browse files
authored
Enforce immutable updates to AdvancedTable @model (#3115)
1 parent 1e794a2 commit ec2e27e

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

showcase/app/controllers/page-components/advanced-table.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,23 @@ export default class PageComponentsAdvancedTableController extends Controller {
424424
console.group('onMultiSelectSelectionChange__demo4');
425425
console.log('Selected Rows Keys:', selectedRowsKeys);
426426
console.groupEnd();
427-
this.multiSelectUserData__demo4.forEach((user) => {
428-
user.isSelected = selectedRowsKeys.includes(String(user.id));
429-
});
427+
this.multiSelectUserData__demo4 = this.multiSelectUserData__demo4.map(
428+
(user) => {
429+
user.isSelected = selectedRowsKeys.includes(String(user.id));
430+
return user;
431+
},
432+
);
430433
}
431434

432435
@action
433436
multiSelectAnimateSelectedUsers_demo4() {
434-
this.multiSelectUserData__demo4.forEach((user) => {
435-
user.isAnimated = user.isSelected ? user.isSelected : false;
436-
});
437+
this.multiSelectUserData__demo4 = this.multiSelectUserData__demo4.map(
438+
(user) => {
439+
user.isAnimated = user.isSelected ? user.isSelected : false;
440+
441+
return user;
442+
},
443+
);
437444

438445
// eslint-disable-next-line ember/no-runloop
439446
later(() => {
@@ -443,9 +450,12 @@ export default class PageComponentsAdvancedTableController extends Controller {
443450

444451
@action
445452
multiSelectResetUserAnimation_demo4() {
446-
this.multiSelectUserData__demo4.forEach((user) => {
447-
user.isAnimated = false;
448-
});
453+
this.multiSelectUserData__demo4 = this.multiSelectUserData__demo4.map(
454+
(user) => {
455+
user.isAnimated = false;
456+
return user;
457+
},
458+
);
449459
}
450460

451461
// Example where dynamically add more focusable elements to a cell

website/docs/components/table/advanced-table/partials/code/component-api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The Advanced Table component itself is where most of the options will be applied
2323
</Doc::ComponentApi>
2424
</C.Property>
2525
<C.Property @name="model" @type="array">
26-
The data model to be used by the Advanced Table. The model can have any shape, but for nested rows there are two expected keys.
26+
The data model to be used by the Advanced Table. **This array should be treated as immutable. Any updates must be made by passing a new array.** The model can have any shape, but for nested rows there are two expected keys.
2727
<Doc::ComponentApi as |C|>
2828
<C.Property @name="children" @type="array">
2929
If there are nested rows, the Advanced Table will use the `children` key in the model to render the child content. The key can be changed by setting `childrenKey` argument on the `Hds::AdvancedTable`.

0 commit comments

Comments
 (0)