Skip to content

Commit 85cfb15

Browse files
committed
Update utils.ts
1 parent e0cf30d commit 85cfb15

2 files changed

Lines changed: 20 additions & 34 deletions

File tree

src/core/scroller.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,26 @@ import {
1616
isInitialMeasurementDone,
1717
} from "./store";
1818
import { 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.

src/core/utils.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff 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-
};

0 commit comments

Comments
 (0)