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

Commit 20e5c18

Browse files
vicbchirayuk
authored andcommitted
fix(ng_repeat): fix ng_repeat not moving views for elements that have not moved
Closes #1154 Closes #1155
1 parent e074663 commit 20e5c18

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

lib/directive/ng_repeat.dart

+7-3
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class NgRepeat {
8787
Function _generateId = (key, value, index) => value;
8888
Watch _watch;
8989

90-
NgRepeat(this._viewPort, this._boundViewFactory, this._scope,
91-
this._parser, this.formatters);
90+
NgRepeat(this._viewPort, this._boundViewFactory, this._scope, this._parser, this.formatters);
9291

9392
set expression(value) {
9493
assert(value != null);
@@ -221,9 +220,14 @@ class NgRepeat {
221220
var changeFn = changeFunctions[targetIndex];
222221
if (changeFn == null) {
223222
rows[targetIndex] = _rows[targetIndex];
224-
domIndex--;
225223
// The element has not moved but `$last` and `$middle` might still need
226224
// to be updated
225+
var childContext = _updateContext(rows[targetIndex].scope.context, targetIndex, length);
226+
if (domIndex < 0 || leftInDom[domIndex] != targetIndex) {
227+
_viewPort.move(rows[targetIndex].view, moveAfter: previousView);
228+
leftInDom.remove(targetIndex);
229+
}
230+
domIndex--;
227231
_updateContext(rows[targetIndex].scope.context, targetIndex, length);
228232
} else {
229233
changeFn(targetIndex, previousView);

test/directive/ng_repeat_spec.dart

+9
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,15 @@ main() {
466466
lis = element.querySelectorAll('li');
467467
});
468468

469+
it(r'should correctly update rows orders - gh1154', () {
470+
scope.context['items'] = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
471+
scope.apply();
472+
expect(element).toHaveText('0123456789');
473+
scope.context['items'] = [1, 2, 6, 7, 4, 3, 5, 8, 9, 0];
474+
scope.apply();
475+
expect(element).toHaveText('0123456789');
476+
});
477+
469478
it(r'should preserve the order of elements', () {
470479
scope.context['items'] = [a, c, d];
471480
scope.apply();

0 commit comments

Comments
 (0)