forked from mystiq/hydrogen-web
Move common code from if-else
Signed-off-by: RMidhunSuresh <rmidhunsuresh@gmail.com>
This commit is contained in:
parent
168312627d
commit
a02b6b68d3
1 changed files with 7 additions and 11 deletions
|
@ -173,7 +173,7 @@ export class LazyListView extends ListView {
|
||||||
this._renderRange = renderRange;
|
this._renderRange = renderRange;
|
||||||
|
|
||||||
const { topCount, renderCount } = this._renderRange;
|
const { topCount, renderCount } = this._renderRange;
|
||||||
const renderedItems = this._itemsFromList(topCount, topCount + renderCount);
|
const renderedItems = this._itemsFromList({ start: topCount, end: topCount + renderCount});
|
||||||
this._adjustPadding(renderRange);
|
this._adjustPadding(renderRange);
|
||||||
this._childInstances = [];
|
this._childInstances = [];
|
||||||
const fragment = document.createDocumentFragment();
|
const fragment = document.createDocumentFragment();
|
||||||
|
@ -185,7 +185,7 @@ export class LazyListView extends ListView {
|
||||||
this._root.appendChild(fragment);
|
this._root.appendChild(fragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
_itemsFromList(start, end) {
|
_itemsFromList({start, end}) {
|
||||||
const array = [];
|
const array = [];
|
||||||
let i = 0;
|
let i = 0;
|
||||||
for (const item of this._list) {
|
for (const item of this._list) {
|
||||||
|
@ -228,22 +228,18 @@ export class LazyListView extends ListView {
|
||||||
|
|
||||||
_renderElementsInRange(range) {
|
_renderElementsInRange(range) {
|
||||||
const diff = this._renderRange.diff(range);
|
const diff = this._renderRange.diff(range);
|
||||||
const {start, end} = diff.toAdd;
|
const renderedItems = this._itemsFromList(diff.toAdd);
|
||||||
const renderedItems = this._itemsFromList(start, end);
|
|
||||||
this._adjustPadding(range);
|
this._adjustPadding(range);
|
||||||
|
|
||||||
if (diff.scrollDirection === ScrollDirection.downwards) {
|
|
||||||
const {start, end} = diff.toRemove;
|
const {start, end} = diff.toRemove;
|
||||||
this._childInstances.splice(0, end - start + 1)
|
const normalizedStart = this._renderRange.normalize(start);
|
||||||
.forEach(child => this._removeChild(child));
|
this._childInstances.splice(normalizedStart, end - start + 1).forEach(child => this._removeChild(child));
|
||||||
|
|
||||||
|
if (diff.scrollDirection === ScrollDirection.downwards) {
|
||||||
const fragment = this._renderedFragment(renderedItems, view => this._childInstances.push(view));
|
const fragment = this._renderedFragment(renderedItems, view => this._childInstances.push(view));
|
||||||
this._root.appendChild(fragment);
|
this._root.appendChild(fragment);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const {start, end} = diff.toRemove;
|
|
||||||
const normalizedStart = this._renderRange.normalize(start);
|
|
||||||
this._childInstances.splice(normalizedStart, end - start + 1)
|
|
||||||
.forEach(child => this._removeChild(child));
|
|
||||||
const fragment = this._renderedFragment(renderedItems, view => this._childInstances.unshift(view));
|
const fragment = this._renderedFragment(renderedItems, view => this._childInstances.unshift(view));
|
||||||
this._root.insertBefore(fragment, this._root.firstChild);
|
this._root.insertBefore(fragment, this._root.firstChild);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue