Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplication of cells while filtering #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 13 additions & 35 deletions addon/components/ember-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export default Component.extend({
// this.cellCount = undefined;
this.contentElement = undefined;
this._cells = A();
this._cellMap = Object.create(null);

// TODO: Super calls should always be at the top of the constructor.
// I had to move the super call after the properties were defined to
Expand Down Expand Up @@ -141,9 +140,6 @@ export default Component.extend({
this._cellLayout.length = numItems;
}

var priorMap = this._cellMap;
var cellMap = Object.create(null);

var index = this._cellLayout.indexAt(this._scrollLeft, this._scrollTop, this._clientWidth, this._clientHeight);
var count = this._cellLayout.count(this._scrollLeft, this._scrollTop, this._clientWidth, this._clientHeight);
var items = this._items;
Expand All @@ -157,40 +153,24 @@ export default Component.extend({

for (i=0; i<count; i++) {
itemIndex = index+i;
itemKey = identity(items.objectAt(itemIndex));
if (priorMap) {
cell = priorMap[itemKey];
}
if (cell) {
newItems.push(itemIndex);
}

for (i=0; i<this._cells.length; i++) {
cell = this._cells[i];
if (newItems.length) {
itemIndex = newItems.pop();
let item = items.objectAt(itemIndex);
itemKey = identity(item);
style = this._cellLayout.formatItemStyle(itemIndex, this._clientWidth, this._clientHeight);
set(cell, 'style', style);
set(cell, 'hidden', false);
set(cell, 'key', itemKey);
set(cell, 'index', itemIndex);
cellMap[itemKey] = cell;
set(cell, 'item', item);
set(cell, 'hidden', false);
} else {
newItems.push(itemIndex);
}
}

for (i=0; i<this._cells.length; i++) {
cell = this._cells[i];
if (!cellMap[cell.key]) {
if (newItems.length) {
itemIndex = newItems.pop();
let item = items.objectAt(itemIndex);
itemKey = identity(item);
style = this._cellLayout.formatItemStyle(itemIndex, this._clientWidth, this._clientHeight);
set(cell, 'style', style);
set(cell, 'key', itemKey);
set(cell, 'index', itemIndex);
set(cell, 'item', item);
set(cell, 'hidden', false);
cellMap[itemKey] = cell;
} else {
set(cell, 'hidden', true);
set(cell, 'style', 'height: 0; display: none;');
}
set(cell, 'hidden', true);
set(cell, 'style', 'height: 0; display: none;');
}
}

Expand All @@ -200,10 +180,8 @@ export default Component.extend({
itemKey = identity(item);
style = this._cellLayout.formatItemStyle(itemIndex, this._clientWidth, this._clientHeight);
cell = new Cell(itemKey, item, itemIndex, style);
cellMap[itemKey] = cell;
this._cells.pushObject(cell);
}
this._cellMap = cellMap;
},

_isGlimmer2() {
Expand Down