forked from mystiq/hydrogen-web
Replace slice with iterator
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
c539c38699
commit
d1f465e6cc
2 changed files with 14 additions and 9 deletions
|
@ -119,10 +119,6 @@ export class SortedMapList extends BaseObservableList {
|
||||||
return this._sourceMap.size;
|
return this._sourceMap.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
slice(start, end) {
|
|
||||||
return this._sortedPairs.slice(start, end);
|
|
||||||
}
|
|
||||||
|
|
||||||
[Symbol.iterator]() {
|
[Symbol.iterator]() {
|
||||||
const it = this._sortedPairs.values();
|
const it = this._sortedPairs.values();
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -112,21 +112,30 @@ export class LazyListView extends ListView {
|
||||||
this._childInstances = [];
|
this._childInstances = [];
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
const view = this._childCreator(item.value);
|
const view = this._childCreator(item);
|
||||||
this._childInstances.push(view);
|
this._childInstances.push(view);
|
||||||
fragment.appendChild(mountView(view, this._mountArgs));
|
fragment.appendChild(mountView(view, this._mountArgs));
|
||||||
}
|
}
|
||||||
this._root.appendChild(fragment);
|
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() {
|
_renderElementsInRange() {
|
||||||
const { topCount, renderCount, bottomCount } = this._renderRange;
|
const { topCount, renderCount, bottomCount } = this._renderRange;
|
||||||
const paddingTop = topCount * this._itemHeight;
|
const paddingTop = topCount * this._itemHeight;
|
||||||
const paddingBottom = bottomCount * this._itemHeight;
|
const paddingBottom = bottomCount * this._itemHeight;
|
||||||
const renderedItems = (this._list || []).slice(
|
const renderedItems = this._itemsFromList(topCount, topCount + renderCount);
|
||||||
topCount,
|
console.log(renderedItems);
|
||||||
topCount + renderCount,
|
|
||||||
);
|
|
||||||
this._root.style.paddingTop = `${paddingTop}px`;
|
this._root.style.paddingTop = `${paddingTop}px`;
|
||||||
this._root.style.paddingBottom = `${paddingBottom}px`;
|
this._root.style.paddingBottom = `${paddingBottom}px`;
|
||||||
this._root.innerHTML = "";
|
this._root.innerHTML = "";
|
||||||
|
|
Loading…
Reference in a new issue