Skip to content

Commit

Permalink
refactor: remove unused Collection.merge() (#619)
Browse files Browse the repository at this point in the history
  • Loading branch information
dilyanpalauzov committed Jun 4, 2020
1 parent 6e0e133 commit d535ccd
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 75 deletions.
23 changes: 0 additions & 23 deletions src/js/common/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,29 +91,6 @@ Collection.or = function(filters) {
};
};

/**
* Merge several collections.
*
* You can\'t merge collections different _getScheduleID functions. Take case of use.
* @param {...Collection} collections collection arguments to merge
* @returns {Collection} merged collection.
*/
Collection.merge = function(collections) { // eslint-disable-line
var cols = aps.call(arguments),
newItems = {},
merged = new Collection(cols[0].getItemID),
extend = util.extend;

forEachArr(cols, function(col) {
extend(newItems, col.items);
});

merged.items = newItems;
merged.length = util.keys(merged.items).length;

return merged;
};

/**********
* prototype props
**********/
Expand Down
52 changes: 0 additions & 52 deletions test/app/common/collection.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -567,58 +567,6 @@ describe('Collection', function() {
});
});

describe('merge()', function() {
it('return new collection with merged supplied collections.', function() {
var item1 = {_id:1},
item2 = {_id:2},
item3 = {_id:5},
c2 = new Collection();

c.add(item1);
c2.add(item2, item3);

var merged = Collection.merge(c, c2);
expect(merged.length).toBe(3);
expect(merged.items).toEqual({
1: item1,
2: item2,
5: item3
});
});

it('newly create collection has same getItemIDFn with first argumented collection.', function() {
var item1 = {_id:1},
item2 = {_id:2},
item3 = {_id:5},
c2 = new Collection();

c.add(item1);
c2.add(item2, item3);

var merged = Collection.merge(c, c2);

expect(merged.getItemID).toBe(c.getItemID);
});

it('item with same id did not affect total item counts', function() {
var item1 = {_id:1},
item2 = {_id:2},
item3 = {_id:5},
item4 = {_id:1, hello: 'world'},
item5 = {_id:2},
item6 = {_id:5},
c2 = new Collection();

c.add(item1, item2, item3);
c2.add(item4, item5, item6);

var merged = Collection.merge(c, c2);

expect(merged.length).toBe(3);
expect(merged.items['1']).toEqual({_id: 1, hello: 'world'});
});
});

describe('toArray()', function() {
it('return new array with collection items.', function() {
var item1 = {_id:1},
Expand Down

0 comments on commit d535ccd

Please sign in to comment.