Skip to content
This repository has been archived by the owner on Feb 22, 2018. It is now read-only.

Commit

Permalink
fix(ng_repeat): fix ng_repeat not moving views for elements that have…
Browse files Browse the repository at this point in the history
… not moved

Closes #1154

Closes #1155
  • Loading branch information
vicb authored and chirayuk committed Jul 24, 2014
1 parent f01e286 commit 559a685
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/directive/ng_repeat.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class NgRepeat {
Function _generateId = (key, value, index) => value;
Watch _watch;

NgRepeat(this._viewPort, this._boundViewFactory, this._scope,
this._parser, this.formatters);
NgRepeat(this._viewPort, this._boundViewFactory, this._scope, this._parser, this.formatters);

set expression(value) {
assert(value != null);
Expand Down Expand Up @@ -221,9 +220,14 @@ class NgRepeat {
var changeFn = changeFunctions[targetIndex];
if (changeFn == null) {
rows[targetIndex] = _rows[targetIndex];
domIndex--;
// The element has not moved but `$last` and `$middle` might still need
// to be updated
var childContext = _updateContext(rows[targetIndex].scope.context, targetIndex, length);
if (domIndex < 0 || leftInDom[domIndex] != targetIndex) {
_viewPort.move(rows[targetIndex].view, moveAfter: previousView);
leftInDom.remove(targetIndex);
}
domIndex--;
_updateContext(rows[targetIndex].scope.context, targetIndex, length);
} else {
changeFn(targetIndex, previousView);
Expand Down
9 changes: 9 additions & 0 deletions test/directive/ng_repeat_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,15 @@ main() {
lis = element.querySelectorAll('li');
});

it(r'should correctly update rows orders - gh1154', () {
scope.context['items'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
scope.apply();
expect(element).toHaveText('0123456789');
scope.context['items'] = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0];
scope.apply();
expect(element).toHaveText('0123456789');
});

it(r'should preserve the order of elements', () {
scope.context['items'] = [a, c, d];
scope.apply();
Expand Down

0 comments on commit 559a685

Please sign in to comment.