ng-virtual-list 20.11.4 → 20.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -275,6 +275,7 @@ const PART_ITEM_FOCUSED = ' item-focused';
275
275
  const MIN_PIXELS_FOR_PREVENT_SNAPPING = 10;
276
276
  const MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL1 = 74;
277
277
  const MAX_VELOCITY_FOR_SCROLL_QUALITY_OPTIMIZATION_LVL2 = 500;
278
+ const MAX_NUMBERS_OF_SKIPS_FOR_QUALITY_OPTIMIZATION_LVL1 = 4;
278
279
  const RANGE_DISPLAY_ITEMS_END_OFFSET = 20;
279
280
  const PREPARE_ITERATIONS = 1;
280
281
  const PREPARATION_REUPDATE_LENGTH = 0;
@@ -1078,6 +1079,7 @@ class TrackBox extends CacheMap {
1078
1079
  _resetBufferSizeTimer;
1079
1080
  _isReseted = true;
1080
1081
  _prerenderedCache = null;
1082
+ _newItems = [];
1081
1083
  lifeCircle() {
1082
1084
  this.fireChangeIfNeed();
1083
1085
  this.fireTick();
@@ -1104,6 +1106,7 @@ class TrackBox extends CacheMap {
1104
1106
  updateCache(previousCollection, currentCollection, itemSize) {
1105
1107
  const trackBy = this._trackingPropertyName;
1106
1108
  let crudDetected = false;
1109
+ this._newItems = [];
1107
1110
  if (!currentCollection || currentCollection.length === 0) {
1108
1111
  if (previousCollection) {
1109
1112
  // deleted
@@ -1171,6 +1174,7 @@ class TrackBox extends CacheMap {
1171
1174
  const item = currentCollection[i], id = item[trackBy];
1172
1175
  if (item && !deletedMap.hasOwnProperty(id) && !updatedMap.hasOwnProperty(id) &&
1173
1176
  !notChangedMap.hasOwnProperty(id)) {
1177
+ this._newItems.push(id);
1174
1178
  // added
1175
1179
  crudDetected = true;
1176
1180
  this._map.set(id, { width: itemSize, height: itemSize, method: ItemDisplayMethods.CREATE });
@@ -1346,7 +1350,7 @@ class TrackBox extends CacheMap {
1346
1350
  const cache = map.get(id);
1347
1351
  componentSize = cache[sizeProperty] > 0 ? cache[sizeProperty] : typicalItemSize;
1348
1352
  itemDisplayMethod = cache?.method ?? ItemDisplayMethods.UPDATE;
1349
- const isItemNew = cache?.[IS_NEW] ?? (this._isLazy && isStart && !this._isReseted);
1353
+ const isItemNew = this._newItems.indexOf(id) > -1 || (this._isLazy && isStart && !this._isReseted);
1350
1354
  isNew = isItemNew;
1351
1355
  if (isNew) {
1352
1356
  isUpdating = true;
@@ -1355,7 +1359,7 @@ class TrackBox extends CacheMap {
1355
1359
  componentSizeDelta = componentSnapshotSize;
1356
1360
  switch (itemDisplayMethod) {
1357
1361
  case ItemDisplayMethods.UPDATE: {
1358
- map.set(id, { ...cache, method: isNew ? ItemDisplayMethods.UPDATE : ItemDisplayMethods.NOT_CHANGED, [IS_NEW]: isNew });
1362
+ map.set(id, { ...cache, method: isNew ? ItemDisplayMethods.UPDATE : ItemDisplayMethods.NOT_CHANGED });
1359
1363
  if (isNew && y <= (scrollSize + size + deltaFromStartCreation + componentSize)) {
1360
1364
  deltaFromStartCreation += componentSizeDelta;
1361
1365
  componentSizeDelta = 0;
@@ -1853,6 +1857,9 @@ class TrackBox extends CacheMap {
1853
1857
  this._prerenderedCache = null;
1854
1858
  }
1855
1859
  }
1860
+ resetCacheChunkInfo() {
1861
+ this._newItems = [];
1862
+ }
1856
1863
  cacheClean() {
1857
1864
  this._map.clear();
1858
1865
  this._snapshot.clear();
@@ -5769,6 +5776,9 @@ class NgVirtualListComponent {
5769
5776
  }), $updateItemsRenderStabilizer = renderStabilizer({
5770
5777
  prepareIterations: PREPARE_ITERATIONS_FOR_UPDATE_ITEMS,
5771
5778
  prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_UPDATE_ITEMS,
5779
+ }), $chunkLoadingRenderStabilizer = renderStabilizer({
5780
+ prepareIterations: PREPARE_ITERATIONS_FOR_UPDATE_ITEMS,
5781
+ prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_UPDATE_ITEMS,
5772
5782
  }), $collapseItemsRenderStabilizer = renderStabilizer({
5773
5783
  prepareIterations: PREPARE_ITERATIONS_FOR_COLLAPSE_ITEMS,
5774
5784
  prepareReupdateLength: PREPARATION_REUPDATE_LENGTH_FOR_COLLAPSE_ITEMS,
@@ -6044,9 +6054,20 @@ class NgVirtualListComponent {
6044
6054
  })).subscribe();
6045
6055
  const $loading = toObservable(this.loading);
6046
6056
  $loading.pipe(takeUntilDestroyed(), distinctUntilChanged(), skip(1), filter$1(v => !v), switchMap$1(() => {
6047
- return $actualItems.pipe(takeUntilDestroyed(this._destroyRef), debounceTime(100), take(1), tap(() => {
6048
- this._scrollerComponent()?.refreshScrollbar();
6049
- }));
6057
+ const scrollbar = this._scrollerComponent();
6058
+ if (!!scrollbar) {
6059
+ scrollbar.stopScrollbar();
6060
+ scrollbar.refreshScrollbar();
6061
+ }
6062
+ return $actualItems.pipe(takeUntilDestroyed(this._destroyRef), take(1), switchMap$1(() => $chunkLoadingRenderStabilizer.pipe(takeUntilDestroyed(this._destroyRef), take(1), tap(() => {
6063
+ console.log('reset');
6064
+ this._trackBox.resetCacheChunkInfo();
6065
+ const scrollbar = this._scrollerComponent();
6066
+ if (!!scrollbar) {
6067
+ scrollbar.stopScrollbar();
6068
+ scrollbar.refreshScrollbar();
6069
+ }
6070
+ }))));
6050
6071
  })).subscribe();
6051
6072
  $loading.pipe(takeUntilDestroyed(), skip(1), distinctUntilChanged(), tap(v => {
6052
6073
  if (v) {
@@ -6162,7 +6183,7 @@ class NgVirtualListComponent {
6162
6183
  }
6163
6184
  };
6164
6185
  let prevItems = [];
6165
- const debouncedUpdate = debounce(update, 0);
6186
+ const debouncedUpdate = debounce(update, 0, MAX_NUMBERS_OF_SKIPS_FOR_QUALITY_OPTIMIZATION_LVL1);
6166
6187
  $viewInit.pipe(takeUntilDestroyed(), filter$1(v => !!v), switchMap$1(() => {
6167
6188
  return combineLatest([$snapScrollToStart, $snapScrollToEnd, $bounds, $listBounds, $scrollEndOffset, $actualItems, $itemConfigMap, $scrollSize, $itemSize,
6168
6189
  $collapsedItemIds, $bufferSize, $maxBufferSize, $snap, $isVertical, $dynamicSize, $enabledBufferOptimization, $cacheVersion, this.$fireUpdate,