211
211
var ngRepeatDirective = [ '$parse' , '$animate' , function ( $parse , $animate ) {
212
212
var NG_REMOVED = '$$NG_REMOVED' ;
213
213
var ngRepeatMinErr = minErr ( 'ngRepeat' ) ;
214
+
215
+ var updateScope = function ( scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength ) {
216
+ // TODO(perf): generate setters to shave off ~40ms or 1-1.5%
217
+ scope [ valueIdentifier ] = value ;
218
+ if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
219
+ scope . $index = index ;
220
+ scope . $first = ( index === 0 ) ;
221
+ scope . $last = ( index === ( arrayLength - 1 ) ) ;
222
+ scope . $middle = ! ( scope . $first || scope . $last ) ;
223
+ // jshint bitwise: false
224
+ scope . $odd = ! ( scope . $even = ( index & 1 ) === 0 ) ;
225
+ // jshint bitwise: true
226
+ } ;
227
+
228
+
214
229
return {
215
230
restrict : 'A' ,
216
231
multiElement : true ,
@@ -291,18 +306,6 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
291
306
$scope [ aliasAs ] = collection ;
292
307
}
293
308
294
- var updateScope = function ( scope , index ) {
295
- scope [ valueIdentifier ] = value ;
296
- if ( keyIdentifier ) scope [ keyIdentifier ] = key ;
297
- scope . $index = index ;
298
- scope . $first = ( index === 0 ) ;
299
- scope . $last = ( index === ( arrayLength - 1 ) ) ;
300
- scope . $middle = ! ( scope . $first || scope . $last ) ;
301
- // jshint bitwise: false
302
- scope . $odd = ! ( scope . $even = ( index & 1 ) === 0 ) ;
303
- // jshint bitwise: true
304
- } ;
305
-
306
309
if ( isArrayLike ( collection ) ) {
307
310
collectionKeys = collection ;
308
311
trackByIdFn = trackByIdExpFn || trackByIdArrayFn ;
@@ -379,7 +382,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
379
382
$animate . move ( getBlockNodes ( block . clone ) , null , jqLite ( previousNode ) ) ;
380
383
}
381
384
previousNode = getBlockEnd ( block ) ;
382
- updateScope ( block . scope , index ) ;
385
+ updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength ) ;
383
386
} else {
384
387
// new item which we don't know about
385
388
$transclude ( function ngRepeatTransclude ( clone , scope ) {
@@ -393,7 +396,7 @@ var ngRepeatDirective = ['$parse', '$animate', function($parse, $animate) {
393
396
// by a directive with templateUrl when its template arrives.
394
397
block . clone = clone ;
395
398
nextBlockMap [ block . id ] = block ;
396
- updateScope ( block . scope , index ) ;
399
+ updateScope ( block . scope , index , valueIdentifier , value , keyIdentifier , key , arrayLength ) ;
397
400
} ) ;
398
401
}
399
402
}
0 commit comments