aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIgor Minar2012-11-23 22:43:30 +0100
committerIgor Minar2012-11-26 21:33:45 +0100
commitcde2f1a868ffacdc592803358130587fd73aca7b (patch)
tree82b18a000f03185f86e30ce6b8a87e5c33984677
parent6a831495dedc81e995bba276084eb3b23643557a (diff)
downloadangular.js-cde2f1a868ffacdc592803358130587fd73aca7b.tar.bz2
fix(ngRepeat): support mostly-stable repeating for primitives
I'm reverting changes that were originally done to ngRepeat to fix #933, because these are now not necessary after the previous changes to keep ngModel always synced with the DOM.
-rw-r--r--src/ng/directive/ngRepeat.js9
-rw-r--r--test/ng/directive/ngRepeatSpec.js18
2 files changed, 19 insertions, 8 deletions
diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js
index 8c934b76..893ad442 100644
--- a/src/ng/directive/ngRepeat.js
+++ b/src/ng/directive/ngRepeat.js
@@ -119,14 +119,7 @@ var ngRepeatDirective = ngDirective({
key = (collection === array) ? index : array[index];
value = collection[key];
- // if value is object, it can be shifted to allow for position change
- // if is not object, need to first check whether index is same to avoid shifting wrong val
- last = isObject(value)
- ? lastOrder.shift(value)
- : (last = lastOrder.peek(value)) && (index === last.index)
- ? lastOrder.shift(value)
- : undefined;
-
+ last = lastOrder.shift(value);
if (last) {
// if we have already seen this object, then we need to reuse the
diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js
index 5442ff39..a45cd972 100644
--- a/test/ng/directive/ngRepeatSpec.js
+++ b/test/ng/directive/ngRepeatSpec.js
@@ -431,5 +431,23 @@ describe('ngRepeat', function() {
expect(newElements[1]).toEqual(lis[1]);
expect(newElements[2]).toEqual(lis[0]);
});
+
+
+ it('should reuse elements even when model is composed of primitives', function() {
+ // rebuilding repeater from scratch can be expensive, we should try to avoid it even for
+ // model that is composed of primitives.
+
+ scope.items = ['hello', 'cau', 'ahoj'];
+ scope.$digest();
+ lis = element.find('li');
+
+ scope.items = ['ahoj', 'hello', 'cau'];
+ scope.$digest();
+ var newLis = element.find('li');
+ expect(newLis.length).toEqual(3);
+ expect(newLis[0]).toEqual(lis[2]);
+ expect(newLis[1]).toEqual(lis[0]);
+ expect(newLis[2]).toEqual(lis[1]);
+ });
});
});