@@ -50,9 +50,8 @@ export default class Virtual {
50
50
private _lastScrollDirection : DIRECTION_TYPE | null = null ;
51
51
// 批量更新相关
52
52
private _pendingUpdates : Set < string | number > = new Set ( ) ;
53
- private _updateTimer : number | null = null ;
54
- // 尺寸变化回调队列
55
- private _sizeChangeCallbacks : Array < ( ) => void > = [ ] ;
53
+ private _updateRAF : number | null = null ;
54
+
56
55
constructor ( param : VirtualParams , callUpdate : ( range : Range ) => void ) {
57
56
this . init ( param , callUpdate ) ;
58
57
}
@@ -87,14 +86,13 @@ export default class Virtual {
87
86
}
88
87
89
88
// 清除批量更新计时器
90
- if ( this . _updateTimer ) {
91
- cancelAnimationFrame ( this . _updateTimer ) ;
92
- this . _updateTimer = null ;
89
+ if ( this . _updateRAF ) {
90
+ cancelAnimationFrame ( this . _updateRAF ) ;
91
+ this . _updateRAF = null ;
93
92
}
94
93
95
- // 清空批量更新队列和回调
94
+ // 清空批量更新队列
96
95
this . _pendingUpdates . clear ( ) ;
97
- this . _sizeChangeCallbacks = [ ] ;
98
96
99
97
if ( this . param && this . callUpdate ) {
100
98
this . checkRange ( 0 , this . param . keeps - 1 ) ;
@@ -201,27 +199,18 @@ export default class Virtual {
201
199
202
200
// 批量更新调度器 - 避免频繁的单次更新
203
201
private _scheduleUpdate ( ) {
204
- if ( this . _updateTimer ) {
202
+ if ( this . _updateRAF ) {
205
203
return ;
206
204
}
207
205
208
- this . _updateTimer = requestAnimationFrame ( ( ) => {
206
+ this . _updateRAF = requestAnimationFrame ( ( ) => {
209
207
if ( this . _pendingUpdates . size > 0 ) {
210
208
// 批量处理所有待更新的项目
211
209
const updatedIds = Array . from ( this . _pendingUpdates ) ;
212
210
this . _batchInvalidateRelatedCaches ( updatedIds ) ;
213
211
this . _pendingUpdates . clear ( ) ;
214
-
215
- // 执行尺寸变化回调
216
- this . _sizeChangeCallbacks . forEach ( ( callback ) => {
217
- try {
218
- callback ( ) ;
219
- } catch ( error ) {
220
- console . warn ( 'Size change callback error:' , error ) ;
221
- }
222
- } ) ;
223
212
}
224
- this . _updateTimer = null ;
213
+ this . _updateRAF = null ;
225
214
} ) ;
226
215
}
227
216
@@ -289,17 +278,6 @@ export default class Virtual {
289
278
}
290
279
}
291
280
292
- // 添加尺寸变化监听器
293
- onSizeChange ( callback : ( ) => void ) {
294
- this . _sizeChangeCallbacks . push ( callback ) ;
295
- return ( ) => {
296
- const index = this . _sizeChangeCallbacks . indexOf ( callback ) ;
297
- if ( index > - 1 ) {
298
- this . _sizeChangeCallbacks . splice ( index , 1 ) ;
299
- }
300
- } ;
301
- }
302
-
303
281
// 简化的尺寸缓存清理 - 优先保留视口附近的尺寸信息
304
282
private _cleanupSizes ( ) {
305
283
if ( this . sizes . size > this . _maxCacheSize * 2 ) { // 降低触发阈值
0 commit comments