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

fix(ng_repeat): fix ng_repeat not moving views for elements that have no... #1155

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
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 @@ -220,9 +219,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
8 changes: 8 additions & 0 deletions test/directive/ng_repeat_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,14 @@ 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];
Expand Down