@infinite-list/data-model
Advanced tools
Comparing version 0.2.15-stillness.1 to 0.2.16
@@ -10,3 +10,2 @@ export declare const DEFAULT_LAYOUT: { | ||
export declare const ON_END_REACHED_HANDLER_TIMEOUT_THRESHOLD = 1000; | ||
export declare const DISPATCH_METRICS_THRESHOLD = 50; | ||
export declare const ON_END_REACHED_THRESHOLD = 2; | ||
@@ -13,0 +12,0 @@ export declare const WINDOW_SIZE = 5; |
@@ -38,3 +38,2 @@ import Batchinator from '@x-oasis/batchinator'; | ||
private _offsetTriggerCachedState; | ||
private _stillnessHelper; | ||
private memoizedResolveSpaceState; | ||
@@ -133,6 +132,4 @@ private memoizedResolveRecycleState; | ||
dispatchScrollMetricsEnabled(): boolean; | ||
stillnessHandler(): void; | ||
isStill(): void; | ||
updateScrollMetrics(scrollMetrics?: ScrollMetrics, useCache?: boolean): void; | ||
} | ||
export default ListDimensions; |
@@ -62,4 +62,2 @@ import BaseDimensions from '../BaseDimensions'; | ||
recycleEnabled?: boolean; | ||
stillnessThreshold?: number; | ||
dispatchMetricsThreshold?: number; | ||
} & BaseDimensionsProps & OnEndReachedHelperProps; | ||
@@ -185,3 +183,2 @@ export declare type ItemsDimensionsProps = BaseDimensionsProps; | ||
targetKey: string; | ||
targetIndex: number; | ||
offset: number; | ||
@@ -188,0 +185,0 @@ } & SpaceStateToken<ItemT, ViewabilityState>; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.15-stillness.1", | ||
"version": "0.2.16", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -12,4 +12,2 @@ export const DEFAULT_LAYOUT = { | ||
export const DISPATCH_METRICS_THRESHOLD = 50; | ||
// 建议 ON_END_REACHED_THRESHOLD * VisibleLength > MAX_TO_RENDER_PER_BATCH * itemLength | ||
@@ -16,0 +14,0 @@ // 这样可以在滚动停止的时候,自动获取一屏幕 |
@@ -15,3 +15,2 @@ import noop from '@x-oasis/noop'; | ||
buildStateTokenIndexKey, | ||
DISPATCH_METRICS_THRESHOLD, | ||
} from './common'; | ||
@@ -49,3 +48,2 @@ import resolveChanged from '@x-oasis/resolve-changed'; | ||
import memoizeOne from 'memoize-one'; | ||
import StillnessHelper from './utils/StillnessHelper'; | ||
@@ -104,4 +102,2 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions { | ||
private _stillnessHelper: StillnessHelper; | ||
private memoizedResolveSpaceState: ( | ||
@@ -133,6 +129,4 @@ state: ListState<ItemT> | ||
persistanceIndices, | ||
stillnessThreshold, | ||
onEndReachedTimeoutThreshold, | ||
onEndReachedHandlerTimeoutThreshold, | ||
dispatchMetricsThreshold = DISPATCH_METRICS_THRESHOLD, | ||
} = props; | ||
@@ -147,3 +141,3 @@ this._keyExtractor = keyExtractor; | ||
this.dispatchMetrics.bind(this), | ||
dispatchMetricsThreshold | ||
50 | ||
); | ||
@@ -158,8 +152,2 @@ this.onEndReachedHelper = new OnEndReachedHelper({ | ||
this.stillnessHandler = this.stillnessHandler.bind(this); | ||
this._stillnessHelper = new StillnessHelper({ | ||
stillnessThreshold, | ||
handler: this.stillnessHandler, | ||
}); | ||
this._deps = deps; | ||
@@ -962,4 +950,3 @@ this._isActive = this.resolveInitialActiveValue(active); | ||
const _targetIndices = this._bufferSet.indices.map((i) => parseInt(i)); | ||
const targetIndices = new Array(_targetIndices.length).fill(null); | ||
const targetIndices = this._bufferSet.indices.map((i) => parseInt(i)); | ||
@@ -979,4 +966,4 @@ // const scrolling = actionType === 'scrollDown' || actionType === 'scrollUp'; | ||
index, | ||
visibleStartIndex - 2, | ||
visibleEndIndex + 2 | ||
visibleStartIndex, | ||
visibleEndIndex | ||
); | ||
@@ -991,4 +978,2 @@ if (position !== null) targetIndices[position] = index; | ||
let _beforeCount = 0; | ||
for ( | ||
@@ -999,24 +984,11 @@ let index = visibleStartIndex, size = beforeSize; | ||
) { | ||
const item = data[index]; | ||
if (!item) continue; | ||
const itemMeta = this.getItemMeta(item, index); | ||
const itemLayout = itemMeta?.getLayout(); | ||
const position = this.getPosition( | ||
index, | ||
bufferedStartIndex, | ||
visibleStartIndex | ||
); | ||
if (_beforeCount < 2 || !itemLayout) { | ||
const position = this.getPosition( | ||
index, | ||
visibleStartIndex - 2, | ||
visibleStartIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
if (index >= this.initialNumToRender) { | ||
_beforeCount++; | ||
} | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
let _afterCount = 0; | ||
for ( | ||
@@ -1027,19 +999,8 @@ let index = visibleEndIndex + 1, size = afterSize; | ||
) { | ||
const item = data[index]; | ||
if (!item) continue; | ||
const itemMeta = this.getItemMeta(item, index); | ||
const itemLayout = itemMeta?.getLayout(); | ||
if (_afterCount < 2 || !itemLayout) { | ||
const position = this.getPosition( | ||
index, | ||
visibleEndIndex + 1, | ||
visibleEndIndex + 2 | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
if (index >= this.initialNumToRender) { | ||
_afterCount++; | ||
} | ||
const position = this.getPosition( | ||
index, | ||
visibleEndIndex + 1, | ||
bufferedEndIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
@@ -1055,35 +1016,3 @@ | ||
let negativeStartIndex = visibleStartIndex - 3; | ||
let positiveStartIndex = visibleEndIndex + 3; | ||
targetIndices.forEach((targetIndex, index) => { | ||
const prevStateResult = this._stateResult as RecycleStateResult<ItemT>; | ||
// targetIndex is null or undefined | ||
if (targetIndex == null) { | ||
if (prevStateResult?.recycleState) { | ||
const _result = prevStateResult.recycleState[index]; | ||
if (_result) { | ||
const { item, targetKey } = _result; | ||
// maybe item has been deleted | ||
if (item === this._data[this.getKeyIndex(targetKey)]) { | ||
const { targetIndex, offset: _offset } = | ||
prevStateResult.recycleState[index]; | ||
if (targetIndex < visibleStartIndex) { | ||
const offset = indexToOffsetMap[negativeStartIndex--]; | ||
recycleStateResult.push({ | ||
...prevStateResult.recycleState[index], | ||
offset: offset || _offset, | ||
}); | ||
} else if (targetIndex > visibleStartIndex) { | ||
const offset = indexToOffsetMap[positiveStartIndex++]; | ||
recycleStateResult.push({ | ||
...prevStateResult.recycleState[index], | ||
offset: offset || _offset, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
return; | ||
} | ||
const item = data[targetIndex]; | ||
@@ -1100,3 +1029,5 @@ if (!item) return; | ||
!this._scrollMetrics || !itemMeta?.getLayout() | ||
? itemMeta.getState() | ||
? itemMeta | ||
? itemMeta.getState() | ||
: {} | ||
: this._configTuple.resolveItemMetaState( | ||
@@ -1115,3 +1046,2 @@ itemMeta, | ||
targetKey: itemKey, | ||
targetIndex, | ||
length: itemLength, | ||
@@ -1132,4 +1062,4 @@ isSpace: false, | ||
const stateResult = { | ||
recycleState: recycleStateResult.filter((v) => v), | ||
spaceState: spaceStateResult.filter((v) => v), | ||
recycleState: recycleStateResult, | ||
spaceState: spaceStateResult, | ||
}; | ||
@@ -1286,3 +1216,5 @@ | ||
!this._scrollMetrics || !itemMeta?.getLayout() | ||
? itemMeta.getState() | ||
? itemMeta | ||
? itemMeta.getState() | ||
: {} | ||
: this._configTuple.resolveItemMetaState( | ||
@@ -1402,10 +1334,2 @@ itemMeta, | ||
stillnessHandler() { | ||
this.dispatchMetrics(this._scrollMetrics); | ||
} | ||
isStill() { | ||
this._stillnessHelper.isStill; | ||
} | ||
/** | ||
@@ -1434,6 +1358,2 @@ * When to trigger updateScrollMetrics.. | ||
if (this._scrollMetrics?.offset !== scrollMetrics?.offset) { | ||
// this._stillnessHelper.startClockBatchinateLast.schedule(); | ||
} | ||
if ( | ||
@@ -1440,0 +1360,0 @@ !this._scrollMetrics || |
@@ -81,6 +81,2 @@ import BaseDimensions from '../BaseDimensions'; | ||
recycleEnabled?: boolean; | ||
stillnessThreshold?: number; | ||
dispatchMetricsThreshold?: number; | ||
} & BaseDimensionsProps & | ||
@@ -247,3 +243,2 @@ OnEndReachedHelperProps; | ||
targetKey: string; | ||
targetIndex: number; | ||
offset: number; | ||
@@ -250,0 +245,0 @@ } & SpaceStateToken<ItemT, ViewabilityState>; |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
1633502
97
19672