@@ -132,17 +132,24 @@ class NgRepeat {
132
132
_watch = _scope.watch (
133
133
_listExpr,
134
134
(CollectionChangeRecord changes, _) {
135
- _onChange ((changes is CollectionChangeRecord ) ? changes : null );
135
+ if (changes is CollectionChangeRecord ) {
136
+ _onCollectionChange (changes);
137
+ } else if (_rows != null ) {
138
+ _rows.forEach ((row) {
139
+ row.scope.destroy ();
140
+ _viewPort.remove (row.view);
141
+ });
142
+ _rows = null ;
143
+ }
136
144
},
137
145
collection: true ,
138
146
formatters: formatters
139
147
);
140
148
}
141
149
142
150
// Computes and executes DOM changes when the item list changes
143
- void _onChange (CollectionChangeRecord changes) {
144
- final iterable = (changes == null ) ? const [] : changes.iterable;
145
- final int length = (changes == null ) ? 0 : changes.length;
151
+ void _onCollectionChange (CollectionChangeRecord changes) {
152
+ final int length = changes.length;
146
153
final rows = new List <_Row >(length);
147
154
final changeFunctions = new List <Function >(length);
148
155
final removedIndexes = < int > [];
@@ -170,51 +177,43 @@ class NgRepeat {
170
177
_rows = new List <_Row >(length);
171
178
for (var i = 0 ; i < length; i++ ) {
172
179
changeFunctions[i] = (index, previousView) {
173
- addRow (index, iterable.elementAt (i), previousView);
180
+ addRow (index, changes. iterable.elementAt (i), previousView);
174
181
};
175
182
}
176
183
} else {
177
- if (changes == null ) {
178
- _rows.forEach ((row) {
179
- row.scope.destroy ();
180
- _viewPort.remove (row.view);
181
- });
182
- leftInDom.clear ();
183
- } else {
184
- changes.forEachRemoval ((CollectionChangeItem removal) {
185
- var index = removal.previousIndex;
186
- var row = _rows[index];
187
- row.scope.destroy ();
188
- _viewPort.remove (row.view);
189
- leftInDom.removeAt (domLength - 1 - index);
190
- });
184
+ changes.forEachRemoval ((CollectionChangeItem removal) {
185
+ var index = removal.previousIndex;
186
+ var row = _rows[index];
187
+ row.scope.destroy ();
188
+ _viewPort.remove (row.view);
189
+ leftInDom.removeAt (domLength - 1 - index);
190
+ });
191
191
192
- changes.forEachAddition ((CollectionChangeItem addition) {
193
- changeFunctions[addition.currentIndex] = (index, previousView) {
194
- addRow (index, addition.item, previousView);
195
- };
196
- });
192
+ changes.forEachAddition ((CollectionChangeItem addition) {
193
+ changeFunctions[addition.currentIndex] = (index, previousView) {
194
+ addRow (index, addition.item, previousView);
195
+ };
196
+ });
197
197
198
- changes.forEachMove ((CollectionChangeItem move) {
199
- var previousIndex = move.previousIndex;
200
- var value = move.item;
201
- changeFunctions[move.currentIndex] = (index, previousView) {
202
- var previousRow = _rows[previousIndex];
203
- var childScope = previousRow.scope;
204
- var childContext = _updateContext (childScope.context, index, length);
205
- if (! identical (childScope.context[_valueIdentifier], value)) {
206
- childContext[_valueIdentifier] = value;
207
- }
208
- rows[index] = _rows[previousIndex];
209
- // Only move the DOM node when required
210
- if (domIndex < 0 || leftInDom[domIndex] != previousIndex) {
211
- _viewPort.move (previousRow.view, moveAfter: previousView);
212
- leftInDom.remove (previousIndex);
213
- }
214
- domIndex-- ;
215
- };
216
- });
217
- }
198
+ changes.forEachMove ((CollectionChangeItem move) {
199
+ var previousIndex = move.previousIndex;
200
+ var value = move.item;
201
+ changeFunctions[move.currentIndex] = (index, previousView) {
202
+ var previousRow = _rows[previousIndex];
203
+ var childScope = previousRow.scope;
204
+ var childContext = _updateContext (childScope.context, index, length);
205
+ if (! identical (childScope.context[_valueIdentifier], value)) {
206
+ childContext[_valueIdentifier] = value;
207
+ }
208
+ rows[index] = _rows[previousIndex];
209
+ // Only move the DOM node when required
210
+ if (domIndex < 0 || leftInDom[domIndex] != previousIndex) {
211
+ _viewPort.move (previousRow.view, moveAfter: previousView);
212
+ leftInDom.remove (previousIndex);
213
+ }
214
+ domIndex-- ;
215
+ };
216
+ });
218
217
}
219
218
220
219
var previousView = null ;
0 commit comments