@infinite-list/data-model
Advanced tools
Comparing version 0.1.1-recycle-alpha.6 to 0.1.1-recycle-alpha.7
@@ -38,2 +38,3 @@ import Batchinator from '@x-oasis/batchinator'; | ||
private _bufferSet; | ||
private _offsetTriggerCachedState; | ||
private memoizedResolveSpaceState; | ||
@@ -95,3 +96,3 @@ private memoizedResolveRecycleState; | ||
addStateListener(listener: StateListener<ItemT>): () => void; | ||
setState(state: ListState<ItemT>): void; | ||
setState(state: ListState<ItemT>, force?: boolean): void; | ||
createSpaceStateToken(options?: Partial<SpaceStateToken<ItemT>>): { | ||
@@ -98,0 +99,0 @@ item: ItemT; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.1.1-recycle-alpha.6", | ||
"version": "0.1.1-recycle-alpha.7", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -95,2 +95,4 @@ import noop from '@x-oasis/noop'; | ||
private _offsetTriggerCachedState = 0; | ||
private memoizedResolveSpaceState: ( | ||
@@ -389,3 +391,3 @@ state: ListState<ItemT> | ||
recalculateRecycleResultState() { | ||
this.setState(this._state); | ||
this.setState(this._state, true); | ||
} | ||
@@ -679,4 +681,5 @@ | ||
updateTheLastItemIntervalValue() { | ||
const index = this._data.length; | ||
const item = this._data[index - 1]; | ||
const len = this._data.length; | ||
const index = len - 1; | ||
const item = this._data[index]; | ||
if (!item) return; | ||
@@ -833,5 +836,7 @@ | ||
setState(state: ListState<ItemT>) { | ||
setState(state: ListState<ItemT>, force = false) { | ||
if (this.fillingMode === FillingMode.SPACE) { | ||
const stateResult = this.memoizedResolveSpaceState(state); | ||
const stateResult = force | ||
? this.resolveSpaceState(state) | ||
: this.memoizedResolveSpaceState(state); | ||
if (typeof this._stateListener === 'function') { | ||
@@ -842,3 +847,5 @@ this._stateListener(stateResult, this._stateResult); | ||
} else if (this.fillingMode === FillingMode.RECYCLE) { | ||
const stateResult = this.memoizedResolveRecycleState(state); | ||
const stateResult = force | ||
? this.resolveRecycleState(state) | ||
: this.memoizedResolveRecycleState(state); | ||
if (typeof this._stateListener === 'function') { | ||
@@ -935,3 +942,3 @@ this._stateListener(stateResult, this._stateResult); | ||
const targetIndices = this._bufferSet.indices; | ||
const targetIndices = this._bufferSet.indices.map((i) => parseInt(i)); | ||
@@ -954,36 +961,30 @@ // const scrolling = actionType === 'scrollDown' || actionType === 'scrollUp'; | ||
const bufferSize = Math.floor( | ||
(this.recycleThreshold - | ||
Math.max(visibleEndIndex - visibleStartIndex, 0)) / | ||
2 | ||
); | ||
const visibleSize = Math.max(visibleEndIndex - visibleStartIndex + 1, 0); | ||
const beforeSize = Math.floor((this.recycleThreshold - visibleSize) / 2); | ||
const afterSize = this.recycleThreshold - visibleSize - beforeSize; | ||
for ( | ||
let index = visibleStartIndex, size = bufferSize; | ||
size >= 0; | ||
let index = visibleStartIndex, size = beforeSize; | ||
size > 0 && index >= 0; | ||
size--, index-- | ||
) { | ||
if (index >= 0) { | ||
const position = this.getPosition( | ||
index, | ||
bufferedStartIndex, | ||
visibleStartIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
const position = this.getPosition( | ||
index, | ||
bufferedStartIndex, | ||
visibleStartIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
for ( | ||
let index = visibleEndIndex + 1, size = bufferSize; | ||
size >= 0; | ||
let index = visibleEndIndex + 1, size = afterSize; | ||
size > 0 && index <= bufferedEndIndex; | ||
size--, index++ | ||
) { | ||
if (index >= 0) { | ||
const position = this.getPosition( | ||
index, | ||
visibleEndIndex + 1, | ||
bufferedEndIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
const position = this.getPosition( | ||
index, | ||
visibleEndIndex + 1, | ||
bufferedEndIndex | ||
); | ||
if (position !== null) targetIndices[position] = index; | ||
} | ||
@@ -1157,2 +1158,3 @@ | ||
this._state = state; | ||
this._offsetTriggerCachedState = scrollMetrics.offset; | ||
@@ -1222,3 +1224,6 @@ if (performItemsMetaChange) { | ||
this._dispatchMetricsBatchinator.schedule(scrollMetrics); | ||
} else if (this._state) { | ||
} else if (scrollMetrics.offset !== this._offsetTriggerCachedState) { | ||
this._scrollMetrics = scrollMetrics; | ||
this._dispatchMetricsBatchinator.schedule(scrollMetrics); | ||
} else { | ||
this._dispatchMetricsBatchinator.dispose({ | ||
@@ -1225,0 +1230,0 @@ abort: true, |
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
1467587
15831