From 0e1545eb04f217f24ecd4e1474cf4cb31c8c3ef0 Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Fri, 31 Aug 2012 13:43:57 -0700 Subject: revert: fix(ng-repeat) to work with primitive types this commit was accidentaly merged. it needs more work and we don't have CLA signature This reverts commit 98d489712eff7559bce87ae53bd242112a875c1a. --- src/apis.js | 10 ---- src/ng/directive/ngRepeat.js | 28 +--------- test/ApiSpecs.js | 4 -- test/ng/directive/ngRepeatSpec.js | 115 -------------------------------------- 4 files changed, 1 insertion(+), 156 deletions(-) diff --git a/src/apis.js b/src/apis.js index 098d9cdd..7b470802 100644 --- a/src/apis.js +++ b/src/apis.js @@ -97,15 +97,5 @@ HashQueueMap.prototype = { return array.shift(); } } - }, - - /** - * return the first item without deleting it - */ - peek: function(key) { - var array = this[key = hashKey(key)]; - if (array) { - return array[0]; - } } }; diff --git a/src/ng/directive/ngRepeat.js b/src/ng/directive/ngRepeat.js index a47b7abc..6dd74ef5 100644 --- a/src/ng/directive/ngRepeat.js +++ b/src/ng/directive/ngRepeat.js @@ -88,7 +88,6 @@ var ngRepeatDirective = ngDirective({ // We need an array of these objects since the same object can be returned from the iterator. // We expect this to be a rare case. var lastOrder = new HashQueueMap(); - var indexValues = []; scope.$watch(function(scope){ var index, length, collection = scope.$eval(rhs), @@ -118,20 +117,7 @@ var ngRepeatDirective = ngDirective({ for (index = 0, length = array.length; index < length; index++) { key = (collection === array) ? index : array[index]; value = collection[key]; - - // if collection is array and value is object, it can be shifted to allow for position change - // if collection is array and value is not object, need to first check whether index is same to - // avoid shifting wrong value - // if collection is not array, need to always check index to avoid shifting wrong value - if (lastOrder.peek(value)) { - last = collection === array ? - ((isObject(value)) ? lastOrder.shift(value) : - (index === lastOrder.peek(value).index ? lastOrder.shift(value) : undefined)) : - (index === lastOrder.peek(value).index ? lastOrder.shift(value) : undefined); - } else { - last = undefined; - } - + last = lastOrder.shift(value); if (last) { // if we have already seen this object, then we need to reuse the // associated scope/element @@ -151,12 +137,6 @@ var ngRepeatDirective = ngDirective({ cursor = last.element; } } else { - if (indexValues.hasOwnProperty(index) && collection !== array) { - var preValue = indexValues[index]; - var v = lastOrder.shift(preValue); - v.element.remove(); - v.scope.$destroy(); - } // new item which we don't know about childScope = scope.$new(); } @@ -178,16 +158,10 @@ var ngRepeatDirective = ngDirective({ index: index }; nextOrder.push(value, last); - indexValues[index] = value; }); } } - var i, l; - for (i = 0, l = indexValues.length - length; i < l; i++) { - indexValues.pop(); - } - //shrink children for (key in lastOrder) { if (lastOrder.hasOwnProperty(key)) { diff --git a/test/ApiSpecs.js b/test/ApiSpecs.js index 1e52cf44..35a85bd4 100644 --- a/test/ApiSpecs.js +++ b/test/ApiSpecs.js @@ -31,11 +31,7 @@ describe('api', function() { map.push('key', 'a'); map.push('key', 'b'); expect(map[hashKey('key')]).toEqual(['a', 'b']); - expect(map.peek('key')).toEqual('a'); - expect(map[hashKey('key')]).toEqual(['a', 'b']); expect(map.shift('key')).toEqual('a'); - expect(map.peek('key')).toEqual('b'); - expect(map[hashKey('key')]).toEqual(['b']); expect(map.shift('key')).toEqual('b'); expect(map.shift('key')).toEqual(undefined); expect(map[hashKey('key')]).toEqual(undefined); diff --git a/test/ng/directive/ngRepeatSpec.js b/test/ng/directive/ngRepeatSpec.js index 83f23cec..72382591 100644 --- a/test/ng/directive/ngRepeatSpec.js +++ b/test/ng/directive/ngRepeatSpec.js @@ -37,89 +37,6 @@ describe('ngRepeat', function() { })); - it('should ngRepeat over array of primitive correctly', inject(function($rootScope, $compile) { - element = $compile( - '