8000 fix(ngRepeat): trigger move animation by pondermatic · Pull Request #15072 · angular/angular.js · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix(ngRepeat): trigger move animation #15072

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix(ngRepeat): correctly re-create last block order when track by is …
…an integer

Merge changes from Narretz@7dbf428.
  • Loading branch information
pondermatic committed Mar 21, 2017
commit c969ae23c48eab32989435d8ed4f9767e89c5ad4
4 changes: 2 additions & 2 deletions src/ng/directive/ngRepeat.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ var ngRepeatDirective = ['$parse', '$animate', '$compile', function($parse, $ani
nextBlockOrder[index] = trackById;
}

// setup lastBlockOrder, used to determine if block moved
// Set up lastBlockOrder. Used to determine if a block moved.
for (key in lastBlockMap) {
lastBlockOrder.push(key);
lastBlockOrder[lastBlockMap[key].index] = key;
}

for (index = 0; index < nextLength; index++) {
Expand Down
51 changes: 51 additions & 0 deletions test/ng/directive/ngRepeatSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1624,4 +1624,55 @@ describe('ngRepeat animations', function() {
expect(item.element.text()).toBe('2');
})
);
Copy link
Contributor
F53F

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put a newline between the two its

it('should maintain the order when the track by expression evaluates to an integer',
inject(function($compile, $rootScope, $animate, $document, $sniffer, $timeout) {
if (!$sniffer.transitions) return;

var item;
var ss = createMockStyleSheet($document);

var items = [
{id: 1, name: 'A'},
{id: 2, name: 'B'},
{id: 4, name: 'C'},
{id: 3, name: 'D'}
];

try {

$animate.enabled(true);

ss.addRule('.animate-me div',
'transition:1s linear all;');

element = $compile(html('<div class="animate-me">' +
'<div ng-repeat="item in items track by item.id">{{ item.name }}</div>' +
'</div>'))($rootScope);

$rootScope.items = [items[0], items[1], items[2]];
$rootScope.$digest();
expect(element.text()).toBe('ABC');

$rootScope.items.push(items[3]);
$rootScope.$digest();

expect(element.text()).toBe('ABCD'); // the original order should be preserved
$animate.flush();
$timeout.flush(1500); // 1s * 1.5 closing buffer
expect(element.text()).toBe('ABCD');

$rootScope.items = [items[0], items[1], items[3]];
$rootScope.$digest();

// The leaving item should maintain it's position until it is removed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's -> its (I know, I added this test ;))

expect(element.text()).toBe('ABCD');
$animate.flush();
$timeout.flush(1500); // 1s * 1.5 closing buffer
expect(element.text()).toBe('ABD');

} finally {
ss.destroy();
}
})
);
});
0