Skip to content

Commit

Permalink
Update utils.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
inokawa committed Dec 4, 2024
1 parent e0cf30d commit 85cfb15
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 34 deletions.
21 changes: 20 additions & 1 deletion src/core/scroller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ import {
isInitialMeasurementDone,
} from "./store";
import { type ScrollToIndexOpts } from "./types";
import { debounce, timeout, clamp, microtask } from "./utils";
import { timeout, clamp, microtask, NULL } from "./utils";

const debounce = <T extends () => void>(fn: T, ms: number) => {
let id: ReturnType<typeof setTimeout> | undefined | null;

const cancel = () => {
if (id != NULL) {
clearTimeout(id);
}
};
const debouncedFn = () => {
cancel();
id = timeout(() => {
id = NULL;
fn();
}, ms);
};
debouncedFn._cancel = cancel;
return debouncedFn;
};

/**
* scrollLeft is negative value in rtl direction.
Expand Down
33 changes: 0 additions & 33 deletions src/core/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,28 +34,6 @@ export const microtask: (fn: () => void) => void =
Promise.resolve().then(fn);
};

/**
* @internal
*/
export const debounce = <T extends () => void>(fn: T, ms: number) => {
let id: ReturnType<typeof setTimeout> | undefined | null;

const cancel = () => {
if (id != NULL) {
clearTimeout(id);
}
};
const debouncedFn = () => {
cancel();
id = timeout(() => {
id = NULL;
fn();
}, ms);
};
debouncedFn._cancel = cancel;
return debouncedFn;
};

/**
* @internal
*/
Expand All @@ -71,14 +49,3 @@ export const once = <V>(fn: () => V): (() => V) => {
return cache;
};
};

/**
* @internal
*/
export const getStyleNumber = (v: string): number => {
if (v) {
return parseFloat(v);
} else {
return 0;
}
};

0 comments on commit 85cfb15

Please sign in to comment.