@@ -84,8 +84,8 @@ class NgRepeatDirective extends AbstractNgRepeatDirective {
84
84
NgRepeatDirective (BlockHole blockHole,
85
85
BoundBlockFactory boundBlockFactory,
86
86
Parser parser,
87
- Scope scope): super (blockHole, boundBlockFactory, parser, scope);
88
- get _shalow => false ;
87
+ Scope scope)
88
+ : super (blockHole, boundBlockFactory, parser, scope) ;
89
89
90
90
get _shallow => false ;
91
91
}
@@ -104,7 +104,7 @@ class NgRepeatDirective extends AbstractNgRepeatDirective {
104
104
* [length] property changes. This means that the repeater will still see
105
105
* additions and deletions but not changes to the array.
106
106
* * The child scopes for each item are created in the lazy mode
107
- * (see [Scope.$new] ). This means the scopes are effectivly taken out of the
107
+ * (see [Scope.$new] ). This means the scopes are effectively taken out of the
108
108
* digest cycle and will not update on changes to the model.
109
109
*
110
110
*/
@@ -134,7 +134,7 @@ abstract class AbstractNgRepeatDirective {
134
134
String _valueIdentifier;
135
135
String _keyIdentifier;
136
136
String _listExpr;
137
- Map <Object , _Row > _rows = new Map < dynamic , _Row >() ;
137
+ Map <dynamic , _Row > _rows = {} ;
138
138
Function _trackByIdFn = (key, value, index) => value;
139
139
Function _removeWatch = () => null ;
140
140
Iterable _lastCollection;
@@ -156,11 +156,12 @@ abstract class AbstractNgRepeatDirective {
156
156
if (trackByExpr != null ) {
157
157
Expression trackBy = _parser (trackByExpr);
158
158
_trackByIdFn = ((key, value, index) {
159
- Map < String , Object > trackByLocals = new Map <String , Object >() ;
159
+ final trackByLocals = < String , Object > {} ;
160
160
if (_keyIdentifier != null ) trackByLocals[_keyIdentifier] = key;
161
- trackByLocals[_valueIdentifier] = value;
162
- trackByLocals[r'$index' ] = index;
163
- trackByLocals[r'$id' ] = (obj) => obj;
161
+ trackByLocals
162
+ ..[_valueIdentifier] = value
163
+ ..[r'$index' ] = index
164
+ ..[r'$id' ] = (obj) => obj;
164
165
return relaxFnArgs (trackBy.eval)(new ScopeLocals (_scope, trackByLocals));
165
166
});
166
167
}
@@ -180,14 +181,12 @@ abstract class AbstractNgRepeatDirective {
180
181
}
181
182
182
183
List <_Row > _computeNewRows (Iterable collection, trackById) {
183
- List < _Row > newRowOrder = [] ;
184
+ final newRowOrder = new List < _Row >(collection.length) ;
184
185
// Same as lastBlockMap but it has the current state. It will become the
185
186
// lastBlockMap on the next iteration.
186
- Map <dynamic , _Row > newRows = new Map <dynamic , _Row >();
187
- var arrayLength = collection.length;
187
+ final newRows = < dynamic , _Row > {};
188
188
// locate existing items
189
- var length = newRowOrder.length = collection.length;
190
- for (var index = 0 ; index < length; index++ ) {
189
+ for (var index = 0 ; index < newRowOrder.length; index++ ) {
191
190
var value = collection.elementAt (index);
192
191
trackById = _trackByIdFn (index, value, index);
193
192
if (_rows.containsKey (trackById)) {
@@ -198,9 +197,7 @@ abstract class AbstractNgRepeatDirective {
198
197
} else if (newRows.containsKey (trackById)) {
199
198
// restore lastBlockMap
200
199
newRowOrder.forEach ((row) {
201
- if (row != null && row.startNode != null ) {
202
- _rows[row.id] = row;
203
- }
200
+ if (row != null && row.startNode != null ) _rows[row.id] = row;
204
201
});
205
202
// This is a duplicate and we need to throw an error
206
203
throw "[NgErr50] ngRepeat error! Duplicates in a repeater are not "
@@ -230,13 +227,11 @@ abstract class AbstractNgRepeatDirective {
230
227
arrayChange = _lastCollection != collection;
231
228
232
229
if (arrayChange) _lastCollection = collection;
233
- if (collection is ! Iterable ) {
234
- collection = [];
235
- }
230
+ if (collection is ! Iterable ) collection = [];
236
231
237
232
List <_Row > newRowOrder = _computeNewRows (collection, trackById);
238
233
239
- for (var index = 0 , length = collection.length ; index < length; index++ ) {
234
+ for (var index = 0 ; index < collection. length; index++ ) {
240
235
var value = collection.elementAt (index);
241
236
_Row row = newRowOrder[index];
242
237
@@ -250,10 +245,8 @@ abstract class AbstractNgRepeatDirective {
250
245
nextNode = nextNode.nextNode;
251
246
} while (nextNode != null );
252
247
253
- if (row.startNode != nextNode) {
254
- // existing item which got moved
255
- row.block.moveAfter (cursor);
256
- }
248
+ // existing item which got moved
249
+ if (row.startNode != nextNode) row.block.moveAfter (cursor);
257
250
previousNode = row.endNode;
258
251
} else {
259
252
// new item which we don't know about
@@ -264,20 +257,19 @@ abstract class AbstractNgRepeatDirective {
264
257
childScope[_valueIdentifier] = value;
265
258
childScope.$dirty ();
266
259
}
267
- childScope[r'$index' ] = index;
268
- childScope[r'$first' ] = (index == 0 );
269
- childScope[r'$last' ] = (index == (collection.length - 1 ));
270
- childScope[r'$middle' ] = ! (childScope.$first || childScope.$last);
271
- childScope[r'$odd' ] = index & 1 == 1 ;
272
- childScope[r'$even' ] = index & 1 == 0 ;
273
- if (arrayChange && _shalow) {
274
- childScope.$dirty ();
275
- }
260
+ childScope
261
+ ..[r'$index' ] = index
262
+ ..[r'$first' ] = (index == 0 )
263
+ ..[r'$last' ] = (index == (collection.length - 1 ))
264
+ ..[r'$middle' ] = ! (childScope.$first || childScope.$last)
265
+ ..[r'$odd' ] = index & 1 == 1
266
+ ..[r'$even' ] = index & 1 == 0 ;
267
+ if (arrayChange && _shallow) childScope.$dirty ();
276
268
277
269
if (row.startNode == null ) {
278
- _rows[row.id] = row;
279
270
var block = _boundBlockFactory (childScope);
280
- row..block = block
271
+ _rows[row.id] = row
272
+ ..block = block
281
273
..scope = childScope
282
274
..elements = block.elements
283
275
..startNode = row.elements[0 ]
0 commit comments