Skip to content

Commit

Permalink
fix(collectionRepeat): remove elements at correct time when leaving page
Browse files Browse the repository at this point in the history
  • Loading branch information
ajoslin committed Jun 11, 2014
1 parent e6f79cc commit 30a3c8e
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 33 deletions.
7 changes: 0 additions & 7 deletions js/angular/service/collectionRepeatDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ function($cacheFactory, $parse, $rootScope) {
destroy: function() {
this.dimensions.length = 0;
this.data = null;
forEach(this.backupItemsArray, function(item) {
this.destroyItem(item);
}, this);
this.backupItemsArray.length = 0;

forEach(this.attachedItems, function(item, key) {
this.destroyItem(item);
}, this);
this.attachedItems = {};
},
calculateDataDimensions: function() {
Expand Down
7 changes: 4 additions & 3 deletions js/angular/service/collectionRepeatManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,10 @@ function($rootScope, $timeout) {

CollectionRepeatManager.prototype = {
destroy: function() {
for (var i in this.renderedItems) {
this.removeItem(i);
}
this.renderedItems = {};
this.render = angular.noop;
this.calculateDimensions = angular.noop;
this.dimensions = [];
},

/*
Expand Down
14 changes: 0 additions & 14 deletions test/unit/angular/service/collectionDataSource.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,6 @@ describe('$collectionDataSource service', function() {
});
});

it('.destroy() should cleanup dimensions backupItemsArray and attachedItems', function() {
var source = setup();
source.dimensions = [1,2,3];
source.attachedItems = {0: 'a'};
source.backupItemsArray = ['b'];
spyOn(source, 'destroyItem');
source.destroy();
expect(source.dimensions.length).toBe(0);
expect(source.destroyItem).toHaveBeenCalledWith('a');
expect(source.destroyItem).toHaveBeenCalledWith('b');
expect(source.attachedItems).toEqual({});
expect(source.backupItemsArray).toEqual([]);
});

it('.calculateDataDimensions()', function() {
function widthGetter(scope, locals) {
return locals.$index + locals.item + 'w';
Expand Down
9 changes: 0 additions & 9 deletions test/unit/angular/service/collectionRepeatManager.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,6 @@ describe('collectionRepeatManager service', function() {

});

it('.destroy() should remove items', function() {
var manager = setup();
spyOn(manager, 'removeItem');
manager.renderedItems = { '1': true, '2': true };
manager.destroy();
expect(manager.removeItem).toHaveBeenCalledWith('1');
expect(manager.removeItem).toHaveBeenCalledWith('2');
});

describe('.calculateDimensions()', function() {
it('should work with 1 item per space', function() {
var manager = setup();
Expand Down

0 comments on commit 30a3c8e

Please sign in to comment.