@@ -20,38 +20,37 @@ export const useRender = (props: Props, viewer: Ref<null|HTMLElement>, scrollOpt
2020 const meta = ref < Array < Meta > > ( [ ] )
2121 const visible = computed ( ( ) => meta . value . filter ( item => item . visible ) )
2222
23- // debouncedWatch(
24- // [() => props.mode, () => props.prev, () => props.current, () => props.inputDelay],
25- // () => { console.log('changed!') },
26- // { debounce: props.inputDelay }
27- // )
23+ const setRender = ( ) => {
24+ const result = renderLines ( props . mode , props . prev , props . current )
25+ render . value = result
26+ meta . value . splice ( render . value . length )
27+
28+ render . value . map ( ( v , index : number ) => {
29+ const item = meta . value [ index ]
30+
31+ if ( scrollOptions . value ) {
32+ meta . value [ index ] = {
33+ index,
34+ visible : item ?. visible || false ,
35+ top : item ?. top || undefined ,
36+ height : item ?. height || scrollOptions . value . lineMinHeight
37+ }
38+ } else {
39+ meta . value [ index ] = {
40+ index,
41+ visible : true
42+ }
43+ }
44+ } )
45+ }
2846
29- watch (
47+ debouncedWatch (
3048 [ ( ) => props . mode , ( ) => props . prev , ( ) => props . current ] ,
31- ( ) => {
32- const result = renderLines ( props . mode , props . prev , props . current )
33- render . value = result
34- meta . value . splice ( render . value . length )
35-
36- render . value . map ( ( v , index : number ) => {
37- const item = meta . value [ index ]
38-
39- if ( scrollOptions . value ) {
40- meta . value [ index ] = {
41- index,
42- visible : item ?. visible || false ,
43- top : item ?. top || undefined ,
44- height : item ?. height || scrollOptions . value . lineMinHeight
45- }
46- } else {
47- meta . value [ index ] = {
48- index,
49- visible : true
50- }
51- }
52- } )
53- } ,
54- { immediate : true }
49+ setRender ,
50+ {
51+ debounce : props . inputDelay ,
52+ immediate : true
53+ }
5554 )
5655
5756 return {
@@ -94,11 +93,14 @@ export const useVirtualScroll = (props: Props, viewer: Ref<null|HTMLElement>, sc
9493 if ( ! scrollOptions . value ) return
9594 viewer . value ?. addEventListener ( 'scroll' , useThrottleFn ( setMeta , scrollOptions . value . scrollDelay ) )
9695
97- // debouncedWatch(
98- // [() => props.mode, () => props.prev, () => props.current, () => props.inputDelay],
99- // () => { console.log('changed!') },
100- // { debounce: props.inputDelay }
101- // )
96+ debouncedWatch (
97+ [ ( ) => props . mode , ( ) => props . prev , ( ) => props . current ] ,
98+ ( ) => nextTick ( setMeta ) ,
99+ {
100+ debounce : props . inputDelay ,
101+ immediate : true
102+ }
103+ )
102104
103105 watch (
104106 [ ( ) => props . mode , ( ) => props . prev , ( ) => props . current ] ,
0 commit comments