File tree Expand file tree Collapse file tree 2 files changed +22
-36
lines changed
Expand file tree Collapse file tree 2 files changed +22
-36
lines changed Original file line number Diff line number Diff line change @@ -16,7 +16,28 @@ import {
1616 isInitialMeasurementDone ,
1717} from "./store" ;
1818import { type ScrollToIndexOpts } from "./types" ;
19- import { debounce , timeout , clamp , microtask } from "./utils" ;
19+ import { clamp , microtask , NULL } from "./utils" ;
20+
21+ const timeout = setTimeout ;
22+
23+ const debounce = < T extends ( ) => void > ( fn : T , ms : number ) => {
24+ let id : ReturnType < typeof setTimeout > | undefined | null ;
25+
26+ const cancel = ( ) => {
27+ if ( id != NULL ) {
28+ clearTimeout ( id ) ;
29+ }
30+ } ;
31+ const debouncedFn = ( ) => {
32+ cancel ( ) ;
33+ id = timeout ( ( ) => {
34+ id = NULL ;
35+ fn ( ) ;
36+ } , ms ) ;
37+ } ;
38+ debouncedFn . _cancel = cancel ;
39+ return debouncedFn ;
40+ } ;
2041
2142/**
2243 * scrollLeft is negative value in rtl direction.
Original file line number Diff line number Diff line change @@ -5,8 +5,6 @@ export const NULL = null;
55export const { min, max, abs, floor } = Math ;
66/** @internal */
77export const values = Object . values ;
8- /** @internal */
9- export const timeout = setTimeout ;
108
119/**
1210 * @internal
@@ -34,28 +32,6 @@ export const microtask: (fn: () => void) => void =
3432 Promise . resolve ( ) . then ( fn ) ;
3533 } ;
3634
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-
5935/**
6036 * @internal
6137 */
@@ -71,14 +47,3 @@ export const once = <V>(fn: () => V): (() => V) => {
7147 return cache ;
7248 } ;
7349} ;
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