Skip to content

Commit

Permalink
adds notification for displayed slice
Browse files Browse the repository at this point in the history
  • Loading branch information
shaunc committed Aug 19, 2015
1 parent 4613ca2 commit b2780fe
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions addon/components/ember-collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,12 +152,14 @@ export default Ember.Component.extend({
var priorMap = this._cellMap;
var cellMap = Object.create(null);

var index = this._cellLayout.indexAt(this._offsetX, this._offsetY, this._width, this._height);
var count = this._cellLayout.count(this._offsetX, this._offsetY, this._width, this._height);
var startingIndex = this._cellLayout.indexAt(
this._offsetX, this._offsetY, this._width, this._height);
var visibleCount = this._cellLayout.count(
this._offsetX, this._offsetY, this._width, this._height);
var items = this._items;
var bufferBefore = Math.min(index, this._buffer);
index -= bufferBefore;
count += bufferBefore;
var bufferBefore = Math.min(startingIndex, this._buffer);
var index = startingIndex - bufferBefore;
var count = visibleCount + bufferBefore;
count = Math.min(count + this._buffer, Ember.get(items, 'length') - index);
var i, pos, width, height, style, itemIndex, itemKey, cell;

Expand Down Expand Up @@ -217,6 +219,14 @@ export default Ember.Component.extend({
cellMap[itemKey] = cell;
this._cells.pushObject(cell);
}
if (this._startingIndex !== startingIndex || this._visibleCount !== visibleCount) {
this._startingIndex = startingIndex;
this._visibleCount = visibleCount;
let listener = this.getAttr('sliceDidChange');
if (listener != null) {
listener(startingIndex, visibleCount);
}
}
this._cellMap = cellMap;
return this._cells;
},
Expand Down

0 comments on commit b2780fe

Please sign in to comment.