@infinite-list/data-model
Advanced tools
Comparing version 0.2.29 to 0.2.30
@@ -9,4 +9,6 @@ import Batchinator from '@x-oasis/batchinator'; | ||
readonly onEndReachedHandlerBatchinator: Batchinator; | ||
readonly _consecutiveDistanceTimeoutThresholdValue = 800; | ||
readonly sendOnEndReachedDistanceFromEndStack: SendOnEndReachedDistanceFromBottomStack; | ||
private onEndReached; | ||
private _scrollMetrics; | ||
private _maxCountOfHandleOnEndReachedAfterStillness; | ||
@@ -16,3 +18,3 @@ private _distanceFromEndThresholdValue; | ||
private _onEndReachedTimeoutHandler; | ||
readonly _consecutiveDistanceTimeoutThresholdValue = 800; | ||
attemptToHandleOnEndReachedBatchinator: Batchinator; | ||
constructor(props: OnEndReachedHelperProps); | ||
@@ -27,6 +29,7 @@ static createStackToken(distanceFromEnd: number): { | ||
setHandler(onEndReached: OnEndReached): void; | ||
perform(scrollMetrics: ScrollMetrics, positive?: boolean): { | ||
perform(scrollMetrics?: ScrollMetrics, positive?: boolean): { | ||
distanceFromEnd: number; | ||
isEndReached: boolean; | ||
}; | ||
attemptToHandleOnEndReached(): void; | ||
clearTimer(): void; | ||
@@ -33,0 +36,0 @@ releaseHandlerMutex(): void; |
{ | ||
"name": "@infinite-list/data-model", | ||
"version": "0.2.29", | ||
"version": "0.2.30", | ||
"files": [ | ||
@@ -5,0 +5,0 @@ "dist", |
@@ -551,5 +551,6 @@ import noop from '@x-oasis/noop'; | ||
// 无脑调用一次触底 | ||
this.onEndReachedHelper.onEndReachedHandler({ | ||
distanceFromEnd: 0, | ||
}); | ||
// this.onEndReachedHelper.onEndReachedHandler({ | ||
// distanceFromEnd: 0, | ||
// }); | ||
this.onEndReachedHelper.attemptToHandleOnEndReachedBatchinator.schedule(); | ||
} | ||
@@ -608,5 +609,3 @@ } | ||
if (this.initialNumToRender) | ||
this.onEndReachedHelper.onEndReachedHandler({ | ||
distanceFromEnd: 0, | ||
}); | ||
this.onEndReachedHelper.attemptToHandleOnEndReachedBatchinator.schedule(); | ||
} | ||
@@ -637,5 +636,3 @@ } | ||
if (!data.length && this.initialNumToRender) { | ||
this.onEndReachedHelper.onEndReachedHandler({ | ||
distanceFromEnd: 0, | ||
}); | ||
this.onEndReachedHelper.attemptToHandleOnEndReachedBatchinator.schedule(); | ||
} | ||
@@ -660,4 +657,8 @@ | ||
// disable onEndReached; which may cause loop | ||
if (this._scrollMetrics) this.dispatchStoreMetrics(this._scrollMetrics); | ||
setTimeout(() => { | ||
if (this._scrollMetrics) this.dispatchStoreMetrics(this._scrollMetrics); | ||
}); | ||
// if (this._scrollMetrics) this.dispatchStoreMetrics(this._scrollMetrics); | ||
// if (this._dataChangeTriggerOnEndReachedTimer) { | ||
@@ -664,0 +665,0 @@ // clearTimeout(this._dataChangeTriggerOnEndReachedTimer); |
@@ -21,5 +21,7 @@ import Batchinator from '@x-oasis/batchinator'; | ||
readonly onEndReachedHandlerBatchinator: Batchinator; | ||
readonly _consecutiveDistanceTimeoutThresholdValue = 800; | ||
readonly sendOnEndReachedDistanceFromEndStack: SendOnEndReachedDistanceFromBottomStack; | ||
private onEndReached: OnEndReached; | ||
private _scrollMetrics: ScrollMetrics; | ||
private _maxCountOfHandleOnEndReachedAfterStillness: number; | ||
@@ -30,3 +32,3 @@ private _distanceFromEndThresholdValue: number; | ||
readonly _consecutiveDistanceTimeoutThresholdValue = 800; | ||
public attemptToHandleOnEndReachedBatchinator: Batchinator; | ||
@@ -60,2 +62,6 @@ constructor(props: OnEndReachedHelperProps) { | ||
); | ||
this.attemptToHandleOnEndReachedBatchinator = new Batchinator( | ||
this.attemptToHandleOnEndReached.bind(this), | ||
50 | ||
); | ||
} | ||
@@ -90,6 +96,10 @@ | ||
*/ | ||
perform(scrollMetrics: ScrollMetrics, positive = false) { | ||
perform( | ||
scrollMetrics: ScrollMetrics = this._scrollMetrics, | ||
positive = false | ||
) { | ||
const { contentLength, offset, visibleLength } = scrollMetrics; | ||
const distanceFromEnd = contentLength - visibleLength - offset; | ||
const threshold = this.onEndReachedThreshold * visibleLength; | ||
this._scrollMetrics = scrollMetrics; | ||
@@ -109,2 +119,12 @@ if (positive && distanceFromEnd < 0) { | ||
attemptToHandleOnEndReached() { | ||
const { isEndReached, distanceFromEnd } = this._scrollMetrics | ||
? this.perform(this._scrollMetrics) | ||
: { | ||
distanceFromEnd: 0, | ||
isEndReached: true, | ||
}; | ||
this.performEndReached({ isEndReached, distanceFromEnd }); | ||
} | ||
clearTimer() { | ||
@@ -111,0 +131,0 @@ if (this._onEndReachedTimeoutHandler) { |
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
1708256
20278