@@ -24,7 +24,6 @@ const template = html<BenchmarkApp>`
24
24
html `
25
25
< data-table
26
26
:rows =${ x => x . rows }
27
- :selectedRowId =${ x => x . selectedRowId }
28
27
@action =${ ( x , c ) => {
29
28
x . onAction ( c . event ) ;
30
29
} }
@@ -66,27 +65,37 @@ export class BenchmarkApp extends FASTElement {
66
65
if ( ! this . rows ) return ;
67
66
68
67
for ( let i = 0 ; i < this . rows . length ; i += 10 ) {
69
- this . rows [ i ] . label += ' !!!' ;
68
+ // make a copy, then update the array using slice. See below for details
69
+ // https://www.fast.design/docs/fast-element/observables-and-state/#observing-arrays
70
+ let rowItem = Object . create ( this . rows [ i ] ) ;
71
+ rowItem . label += ' !!!' ;
72
+ this . rows . splice ( i , 1 , rowItem ) ;
70
73
}
71
-
72
- this . triggerRerender ( ) ;
73
74
}
74
75
75
76
deleteAllRows ( ) {
76
77
this . rows = [ ] ;
77
78
}
78
79
80
+ /**
81
+ * The observation system cannot track changes made directly
82
+ * through an index update. e.g. arr[3] = 'new value';.
83
+ * This is due to a limitation in JavaScript.
84
+ *
85
+ * To work around this, update arrays with the
86
+ * equivalent splice code e.g. arr.splice(3, 1, 'new value');
87
+ *
88
+ * https://www.fast.design/docs/fast-element/observables-and-state/#observing-arrays
89
+ */
79
90
swapTwoRows ( ) {
80
91
if ( ! this . rows ) return ;
81
92
82
93
if ( this . rows . length > 998 ) {
83
94
const secondRow = this . rows [ 1 ] ;
84
95
const secondToLastRow = this . rows [ 998 ] ;
85
- this . rows [ 1 ] = secondToLastRow ;
86
- this . rows [ 998 ] = secondRow ;
96
+ this . rows . splice ( 1 , 1 , secondToLastRow ) ;
97
+ this . rows . splice ( 998 , 1 , secondRow ) ;
87
98
}
88
-
89
- this . triggerRerender ( ) ;
90
99
}
91
100
92
101
deleteSingleRow ( rowId : number ) {
@@ -112,10 +121,4 @@ export class BenchmarkApp extends FASTElement {
112
121
113
122
throw new Error ( 'unknown event name!' ) ;
114
123
}
115
-
116
- private triggerRerender ( ) {
117
- if ( ! this . rows ) return ;
118
- // trigger an update
119
- this . rows = this . rows . slice ( ) ;
120
- }
121
124
}
0 commit comments