@@ -42,6 +42,14 @@ export interface Rect {
42
42
height : number
43
43
}
44
44
45
+ export type NotifySource =
46
+ | 'noScrollElement'
47
+ | 'observeElementRect'
48
+ | 'observeElementOffset'
49
+ | 'measureItem'
50
+ | 'resizeItem'
51
+ | 'measure'
52
+
45
53
//
46
54
47
55
export const defaultKeyExtractor = ( index : number ) => index
@@ -303,6 +311,7 @@ export interface VirtualizerOptions<
303
311
onChange ?: (
304
312
instance : Virtualizer < TScrollElement , TItemElement > ,
305
313
sync : boolean ,
314
+ source : NotifySource ,
306
315
) => void
307
316
measureElement ?: (
308
317
element : TItemElement ,
@@ -421,8 +430,8 @@ export class Virtualizer<
421
430
}
422
431
}
423
432
424
- private notify = ( sync : boolean ) => {
425
- this . options . onChange ?.( this , sync )
433
+ private notify = ( sync : boolean , source : NotifySource ) => {
434
+ this . options . onChange ?.( this , sync , source )
426
435
}
427
436
428
437
private maybeNotify = memo (
@@ -435,8 +444,8 @@ export class Virtualizer<
435
444
this . range ? this . range . endIndex : null ,
436
445
]
437
446
} ,
438
- ( isScrolling ) => {
439
- this . notify ( isScrolling )
447
+ ( isScrolling ) => ( source : NotifySource ) => {
448
+ this . notify ( isScrolling , source )
440
449
} ,
441
450
{
442
451
key : process . env . NODE_ENV !== 'production' && 'maybeNotify' ,
@@ -472,7 +481,7 @@ export class Virtualizer<
472
481
this . cleanup ( )
473
482
474
483
if ( ! scrollElement ) {
475
- this . maybeNotify ( )
484
+ this . maybeNotify ( ) ( 'noScrollElement' )
476
485
return
477
486
}
478
487
@@ -496,7 +505,7 @@ export class Virtualizer<
496
505
this . unsubs . push (
497
506
this . options . observeElementRect ( this , ( rect ) => {
498
507
this . scrollRect = rect
499
- this . maybeNotify ( )
508
+ this . maybeNotify ( ) ( 'observeElementRect' )
500
509
} ) ,
501
510
)
502
511
@@ -510,8 +519,7 @@ export class Virtualizer<
510
519
: null
511
520
this . scrollOffset = offset
512
521
this . isScrolling = isScrolling
513
-
514
- this . maybeNotify ( )
522
+ this . maybeNotify ( ) ( 'observeElementOffset' )
515
523
} ) ,
516
524
)
517
525
}
@@ -795,7 +803,7 @@ export class Virtualizer<
795
803
this . pendingMeasuredCacheIndexes . push ( item . index )
796
804
this . itemSizeCache = new Map ( this . itemSizeCache . set ( item . key , size ) )
797
805
798
- this . notify ( false )
806
+ this . notify ( false , 'resizeItem' )
799
807
}
800
808
}
801
809
@@ -1048,7 +1056,7 @@ export class Virtualizer<
1048
1056
1049
1057
measure = ( ) => {
1050
1058
this . itemSizeCache = new Map ( )
1051
- this . notify ( false )
1059
+ this . notify ( false , 'measure' )
1052
1060
}
1053
1061
}
1054
1062
0 commit comments