From 9fdfebf00db0646e915a9373dba1619693d8953c Mon Sep 17 00:00:00 2001 From: RMidhunSuresh Date: Fri, 16 Jul 2021 14:19:48 +0530 Subject: [PATCH] Replace get with iterator and remove lambda Signed-off-by: RMidhunSuresh --- src/platform/web/ui/general/LazyListView.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/platform/web/ui/general/LazyListView.js b/src/platform/web/ui/general/LazyListView.js index 4fc581f5..c5b47059 100644 --- a/src/platform/web/ui/general/LazyListView.js +++ b/src/platform/web/ui/general/LazyListView.js @@ -118,6 +118,17 @@ export class LazyListView extends ListView { return array; } + _itemAtIndex(idx) { + let i = 0; + for (const item of this._list) { + if (i === idx) { + return item; + } + i = i + 1; + } + return null; + } + _renderElementsInRange() { const { topCount, renderCount, bottomCount } = this._renderRange; const paddingTop = topCount * this._itemHeight; @@ -196,18 +207,17 @@ export class LazyListView extends ListView { _renderAdditionalElement(fromIdx, toIdx) { const {topCount, renderCount} = this._renderRange; - const childFromIndex = index => this._childCreator(this._list.get(index)); if (toIdx < fromIdx) { // Element is moved up the list, so render element from top boundary const index = topCount; - const child = childFromIndex(index); + const child = this._childCreator(this._itemAtIndex(index)); this._childInstances.unshift(child); this._root.insertBefore(mountView(child, this._mountArgs), this._root.firstChild); } else { // Element is moved down the list, so render element from bottom boundary const index = topCount + renderCount - 1; - const child = childFromIndex(index); + const child = this._childCreator(this._itemAtIndex(index)); this._childInstances.push(child); this._root.appendChild(mountView(child, this._mountArgs)); }