Skip to content

Commit 30a3c8e

Browse files
committed
fix(collectionRepeat): remove elements at correct time when leaving page
1 parent e6f79cc commit 30a3c8e

File tree

4 files changed

+4
-33
lines changed

4 files changed

+4
-33
lines changed

Diff for: js/angular/service/collectionRepeatDataSource.js

-7
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,7 @@ function($cacheFactory, $parse, $rootScope) {
4848
destroy: function() {
4949
this.dimensions.length = 0;
5050
this.data = null;
51-
forEach(this.backupItemsArray, function(item) {
52-
this.destroyItem(item);
53-
}, this);
5451
this.backupItemsArray.length = 0;
55-
56-
forEach(this.attachedItems, function(item, key) {
57-
this.destroyItem(item);
58-
}, this);
5952
this.attachedItems = {};
6053
},
6154
calculateDataDimensions: function() {

Diff for: js/angular/service/collectionRepeatManager.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,10 @@ function($rootScope, $timeout) {
7878

7979
CollectionRepeatManager.prototype = {
8080
destroy: function() {
81-
for (var i in this.renderedItems) {
82-
this.removeItem(i);
83-
}
81+
this.renderedItems = {};
82+
this.render = angular.noop;
83+
this.calculateDimensions = angular.noop;
84+
this.dimensions = [];
8485
},
8586

8687
/*

Diff for: test/unit/angular/service/collectionDataSource.unit.js

-14
Original file line numberDiff line numberDiff line change
@@ -70,20 +70,6 @@ describe('$collectionDataSource service', function() {
7070
});
7171
});
7272

73-
it('.destroy() should cleanup dimensions backupItemsArray and attachedItems', function() {
74-
var source = setup();
75-
source.dimensions = [1,2,3];
76-
source.attachedItems = {0: 'a'};
77-
source.backupItemsArray = ['b'];
78-
spyOn(source, 'destroyItem');
79-
source.destroy();
80-
expect(source.dimensions.length).toBe(0);
81-
expect(source.destroyItem).toHaveBeenCalledWith('a');
82-
expect(source.destroyItem).toHaveBeenCalledWith('b');
83-
expect(source.attachedItems).toEqual({});
84-
expect(source.backupItemsArray).toEqual([]);
85-
});
86-
8773
it('.calculateDataDimensions()', function() {
8874
function widthGetter(scope, locals) {
8975
return locals.$index + locals.item + 'w';

Diff for: test/unit/angular/service/collectionRepeatManager.unit.js

-9
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,6 @@ describe('collectionRepeatManager service', function() {
168168

169169
});
170170

171-
it('.destroy() should remove items', function() {
172-
var manager = setup();
173-
spyOn(manager, 'removeItem');
174-
manager.renderedItems = { '1': true, '2': true };
175-
manager.destroy();
176-
expect(manager.removeItem).toHaveBeenCalledWith('1');
177-
expect(manager.removeItem).toHaveBeenCalledWith('2');
178-
});
179-
180171
describe('.calculateDimensions()', function() {
181172
it('should work with 1 item per space', function() {
182173
var manager = setup();

0 commit comments

Comments
 (0)