File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -16,7 +16,26 @@ import {
1616 isInitialMeasurementDone ,
1717} from "./store" ;
1818import { type ScrollToIndexOpts } from "./types" ;
19- import { debounce , timeout , clamp , microtask } from "./utils" ;
19+ import { timeout , clamp , microtask , NULL } from "./utils" ;
20+
21+ const debounce = < T extends ( ) => void > ( fn : T , ms : number ) => {
22+ let id : ReturnType < typeof setTimeout > | undefined | null ;
23+
24+ const cancel = ( ) => {
25+ if ( id != NULL ) {
26+ clearTimeout ( id ) ;
27+ }
28+ } ;
29+ const debouncedFn = ( ) => {
30+ cancel ( ) ;
31+ id = timeout ( ( ) => {
32+ id = NULL ;
33+ fn ( ) ;
34+ } , ms ) ;
35+ } ;
36+ debouncedFn . _cancel = cancel ;
37+ return debouncedFn ;
38+ } ;
2039
2140/**
2241 * scrollLeft is negative value in rtl direction.
Original file line number Diff line number Diff line change @@ -34,28 +34,6 @@ export const microtask: (fn: () => void) => void =
3434 Promise . resolve ( ) . then ( fn ) ;
3535 } ;
3636
37- /**
38- * @internal
39- */
40- export const debounce = < T extends ( ) => void > ( fn : T , ms : number ) => {
41- let id : ReturnType < typeof setTimeout > | undefined | null ;
42-
43- const cancel = ( ) => {
44- if ( id != NULL ) {
45- clearTimeout ( id ) ;
46- }
47- } ;
48- const debouncedFn = ( ) => {
49- cancel ( ) ;
50- id = timeout ( ( ) => {
51- id = NULL ;
52- fn ( ) ;
53- } , ms ) ;
54- } ;
55- debouncedFn . _cancel = cancel ;
56- return debouncedFn ;
57- } ;
58-
5937/**
6038 * @internal
6139 */
@@ -71,14 +49,3 @@ export const once = <V>(fn: () => V): (() => V) => {
7149 return cache ;
7250 } ;
7351} ;
74-
75- /**
76- * @internal
77- */
78- export const getStyleNumber = ( v : string ) : number => {
79- if ( v ) {
80- return parseFloat ( v ) ;
81- } else {
82- return 0 ;
83- }
84- } ;
You can’t perform that action at this time.
0 commit comments