@@ -425,16 +425,17 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
425
425
//watch props
426
426
$scope . $watchCollection ( rhs , function ngRepeatAction ( collection ) {
427
427
var
428
- block , // last object information {scope, element, id}
429
- collectionKey ,
428
+ block , // last object information {scope, element, id}
429
+ collectionIsLikeArray ,
430
430
collectionKeys = [ ] ,
431
431
elementsToRemove ,
432
- index , key , value , // key/value of iteration
432
+ index , key , value ,
433
433
lastBlockOrder = [ ] ,
434
434
lastKey ,
435
435
nextBlockMap = createMap ( ) ,
436
436
nextBlockOrder = [ ] ,
437
- nextKey , nextLength ,
437
+ nextKey ,
438
+ nextLength ,
438
439
previousNode = $element [ 0 ] , // node that cloned nodes should be inserted after
439
440
// initialized to the comment node anchor
440
441
trackById ,
@@ -445,23 +446,23 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
445
446
}
446
447
447
448
// get collectionKeys
448
- if ( isArrayLike ( collection ) ) {
449
- collectionKeys = collection ;
449
+ collectionIsLikeArray = isArrayLike ( collection ) ;
450
+ if ( collectionIsLikeArray ) {
450
451
trackByIdFn = trackByIdExpFn || trackByIdArrayFn ;
451
452
} else {
452
453
trackByIdFn = trackByIdExpFn || trackByIdObjFn ;
453
454
// if object, extract keys, in enumeration order, unsorted
454
- for ( collectionKey in collection ) {
455
- if ( hasOwnProperty . call ( collection , collectionKey ) && collectionKey . charAt ( 0 ) !== '$' ) {
456
- collectionKeys . push ( collectionKey ) ;
455
+ for ( key in collection ) {
456
+ if ( hasOwnProperty . call ( collection , key ) && key . charAt ( 0 ) !== '$' ) {
457
+ collectionKeys . push ( key ) ;
457
458
}
458
459
}
459
460
}
460
- nextLength = collectionKeys . length ;
461
+ nextLength = collectionIsLikeArray ? collection . length : collectionKeys . length ;
461
462
462
463
// setup nextBlockMap
463
464
for ( index = 0 ; index < nextLength ; index ++ ) {
464
- key = ( collection === collectionKeys ) ? index : collectionKeys [ index ] ;
465
+ key = collectionIsLikeArray ? index : collectionKeys [ index ] ;
465
466
value = collection [ key ] ;
466
467
trackById = trackByIdFn ( key , value , index ) ;
467
468
@@ -472,16 +473,17 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
472
473
expression , trackById , value ) ;
473
474
}
474
475
475
- nextBlockMap [ trackById ] = { id : trackById , clone : undefined , scope : undefined , index : index , key : key , value : value } ;
476
+ nextBlockMap [ trackById ] = { id : trackById , clone : undefined , scope : undefined , index : index } ;
476
477
nextBlockOrder [ index ] = trackById ;
477
478
}
478
479
479
480
// setup lastBlockOrder, used to determine if block moved
480
- for ( lastKey in lastBlockMap ) {
481
- lastBlockOrder . push ( lastKey ) ;
481
+ for ( key in lastBlockMap ) {
482
+ lastBlockOrder . push ( key ) ;
482
483
}
483
484
484
485
for ( index = 0 ; index < nextLength ; index ++ ) {
486
+ key = collectionIsLikeArray ? index : collectionKeys [ index ] ;
485
487
nextKey = nextBlockOrder [ index ] ;
486
488
487
489
if ( lastBlockMap [ nextKey ] ) {
@@ -501,9 +503,7 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
501
503
block . index = nextBlockMap [ nextKey ] . index ;
502
504
}
503
505
504
- updateScope ( block . scope , index ,
505
- valueIdentifier , nextBlockMap [ nextKey ] . value ,
506
- keyIdentifier , nextBlockMap [ nextKey ] . key , nextLength ) ;
506
+ updateScope ( block . scope , index , valueIdentifier , collection [ key ] , keyIdentifier , key , nextLength ) ;
507
507
508
508
nextBlockMap [ nextKey ] = block ;
509
509
previousNode = getBlockEnd ( block ) ;
@@ -524,24 +524,19 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
524
524
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
525
525
// by a directive with templateUrl when its template arrives.
526
526
nextBlockMap [ nextKey ] . clone = clone ;
527
- updateScope ( scope , nextBlockMap [ nextKey ] . index ,
528
- valueIdentifier , nextBlockMap [ nextKey ] . value ,
529
- keyIdentifier , nextBlockMap [ nextKey ] . key , nextLength ) ;
530
-
531
- delete nextBlockMap [ nextKey ] . key ;
532
- delete nextBlockMap [ nextKey ] . value ;
527
+ updateScope ( scope , nextBlockMap [ nextKey ] . index , valueIdentifier , collection [ key ] , keyIdentifier , key , nextLength ) ;
533
528
} ) ;
534
529
}
535
530
}
536
531
537
532
// leave
538
533
// This must go after enter and move because leave prevents getting element's parent.
539
- for ( lastKey in lastBlockMap ) {
540
- if ( nextBlockMap [ lastKey ] ) {
534
+ for ( key in lastBlockMap ) {
535
+ if ( nextBlockMap [ key ] ) {
541
536
continue ;
542
537
}
543
538
544
- block = lastBlockMap [ lastKey ] ;
539
+ block = lastBlockMap [ key ] ;
545
540
elementsToRemove = getBlockNodes ( block . clone ) ;
546
541
$animate . leave ( elementsToRemove ) ;
547
542
block . scope . $destroy ( ) ;
0 commit comments