Replace slice with iterator

Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
RMidhunSuresh 2021-07-13 18:13:45 +05:30
parent c539c38699
commit d1f465e6cc
2 changed files with 14 additions and 9 deletions

View file

@ -119,10 +119,6 @@ export class SortedMapList extends BaseObservableList {
return this._sourceMap.size;
}
slice(start, end) {
return this._sortedPairs.slice(start, end);
}
[Symbol.iterator]() {
const it = this._sortedPairs.values();
return {

View file

@ -112,21 +112,30 @@ export class LazyListView extends ListView {
this._childInstances = [];
const fragment = document.createDocumentFragment();
for (const item of items) {
const view = this._childCreator(item.value);
const view = this._childCreator(item);
this._childInstances.push(view);
fragment.appendChild(mountView(view, this._mountArgs));
}
this._root.appendChild(fragment);
}
_itemsFromList(start, end) {
const array = [];
let i = 0;
for (const item of this._list) {
if (i >= start && i < end) {
array.push(item);
}
i = i + 1;
}
return array;
}
_renderElementsInRange() {
const { topCount, renderCount, bottomCount } = this._renderRange;
const paddingTop = topCount * this._itemHeight;
const paddingBottom = bottomCount * this._itemHeight;
const renderedItems = (this._list || []).slice(
topCount,
topCount + renderCount,
);
const renderedItems = this._itemsFromList(topCount, topCount + renderCount);
console.log(renderedItems);
this._root.style.paddingTop = `${paddingTop}px`;
this._root.style.paddingBottom = `${paddingBottom}px`;
this._root.innerHTML = "";