@@ -433,16 +433,17 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
433
433
//watch props
434
434
$scope . $watchCollection ( rhs , function ngRepeatAction ( collection ) {
435
435
var
436
- block , // last object information {scope, element, id}
437
- collectionKey ,
436
+ block , // last object information {scope, element, id}
437
+ collectionIsLikeArray ,
438
438
collectionKeys = [ ] ,
439
439
elementsToRemove ,
440
- index , key , value , // key/value of iteration
440
+ index , key , value ,
441
441
lastBlockOrder = [ ] ,
442
442
lastKey ,
443
443
nextBlockMap = createMap ( ) ,
444
444
nextBlockOrder = [ ] ,
445
- nextKey , nextLength ,
445
+ nextKey ,
446
+ nextLength ,
446
447
previousNode = $element [ 0 ] , // node that cloned nodes should be inserted after
447
448
// initialized to the comment node anchor
448
449
trackById ,
@@ -453,23 +454,23 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
453
454
}
454
455
455
456
// get collectionKeys
456
- if ( isArrayLike ( collection ) ) {
457
- collectionKeys = collection ;
457
+ collectionIsLikeArray = isArrayLike ( collection ) ;
458
+ if ( collectionIsLikeArray ) {
458
459
trackByIdFn = trackByIdExpFn || trackByIdArrayFn ;
459
460
} else {
460
461
trackByIdFn = trackByIdExpFn || trackByIdObjFn ;
461
462
// if object, extract keys, in enumeration order, unsorted
462
- for ( collectionKey in collection ) {
463
- if ( hasOwnProperty . call ( collection , collectionKey ) && collectionKey . charAt ( 0 ) !== '$' ) {
464
- collectionKeys . push ( collectionKey ) ;
463
+ for ( key in collection ) {
464
+ if ( hasOwnProperty . call ( collection , key ) && key . charAt ( 0 ) !== '$' ) {
465
+ collectionKeys . push ( key ) ;
465
466
}
466
467
}
467
468
}
468
- nextLength = collectionKeys . length ;
469
+ nextLength = collectionIsLikeArray ? collection . length : collectionKeys . length ;
469
470
470
471
// setup nextBlockMap
471
472
for ( index = 0 ; index < nextLength ; index ++ ) {
472
- key = ( collection === collectionKeys ) ? index : collectionKeys [ index ] ;
473
+ key = collectionIsLikeArray ? index : collectionKeys [ index ] ;
473
474
value = collection [ key ] ;
474
475
trackById = trackByIdFn ( key , value , index ) ;
475
476
@@ -480,16 +481,17 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
480
481
expression , trackById , value ) ;
481
482
}
482
483
483
- nextBlockMap [ trackById ] = { id : trackById , clone : undefined , scope : undefined , index : index , key : key , value : value } ;
484
+ nextBlockMap [ trackById ] = { id : trackById , clone : undefined , scope : undefined , index : index } ;
484
485
nextBlockOrder [ index ] = trackById ;
485
486
}
486
487
487
488
// setup lastBlockOrder, used to determine if block moved
488
- for ( lastKey in lastBlockMap ) {
489
- lastBlockOrder . push ( lastKey ) ;
489
+ for ( key in lastBlockMap ) {
490
+ lastBlockOrder . push ( key ) ;
490
491
}
491
492
492
493
for ( index = 0 ; index < nextLength ; index ++ ) {
494
+ key = collectionIsLikeArray ? index : collectionKeys [ index ] ;
493
495
nextKey = nextBlockOrder [ index ] ;
494
496
495
497
if ( lastBlockMap [ nextKey ] ) {
@@ -509,9 +511,7 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
509
511
block . index = nextBlockMap [ nextKey ] . index ;
510
512
}
511
513
512
- updateScope ( block . scope , index ,
513
- valueIdentifier , nextBlockMap [ nextKey ] . value ,
514
- keyIdentifier , nextBlockMap [ nextKey ] . key , nextLength ) ;
514
+ updateScope ( block . scope , index , valueIdentifier , collection [ key ] , keyIdentifier , key , nextLength ) ;
515
515
516
516
nextBlockMap [ nextKey ] = block ;
517
517
previousNode = getBlockEnd ( block ) ;
@@ -532,24 +532,19 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
532
532
// However, we need to keep the reference to the jqlite wrapper as it might be changed later
533
533
// by a directive with templateUrl when its template arrives.
534
534
nextBlockMap [ nextKey ] . clone = clone ;
535
- updateScope ( scope , nextBlockMap [ nextKey ] . index ,
536
- valueIdentifier , nextBlockMap [ nextKey ] . value ,
537
- keyIdentifier , nextBlockMap [ nextKey ] . key , nextLength ) ;
538
-
539
- delete nextBlockMap [ nextKey ] . key ;
540
- delete nextBlockMap [ nextKey ] . value ;
535
+ updateScope ( scope , nextBlockMap [ nextKey ] . index , valueIdentifier , collection [ key ] , keyIdentifier , key , nextLength ) ;
541
536
} ) ;
542
537
}
543
538
}
544
539
545
540
// leave
546
541
// This must go after enter and move because leave prevents getting element's parent.
547
- for ( lastKey in lastBlockMap ) {
548
- if ( nextBlockMap [ lastKey ] ) {
542
+ for ( key in lastBlockMap ) {
543
+ if ( nextBlockMap [ key ] ) {
549
544
continue ;
550
545
}
551
546
552
- block = lastBlockMap [ lastKey ] ;
547
+ block = lastBlockMap [ key ] ;
553
548
elementsToRemove = getBlockNodes ( block . clone ) ;
554
549
$animate . leave ( elementsToRemove ) ;
555
550
block . scope . $destroy ( ) ;
0 commit comments