diff --git a/bun.lockb b/bun.lockb index f6a66cd..810c186 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index c39ed2b..3e5ed53 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "dependencies": { "@solid-primitives/clipboard": "^1.5.10", "@solid-primitives/i18n": "^2.1.1", + "@solid-primitives/scheduled": "^1.4.4", "@solid-primitives/storage": "^4.2.1", "@solidjs/meta": "^0.29.4", "@solidjs/router": "^0.15.2", diff --git a/src/components/filetree.tsx b/src/components/filetree.tsx index 9515cd1..2cdbae5 100644 --- a/src/components/filetree.tsx +++ b/src/components/filetree.tsx @@ -1,8 +1,8 @@ import { Accessor, Component, createContext, createSignal, For, JSX, Show, useContext } from "solid-js"; import { AiFillFile, AiFillFolder, AiFillFolderOpen } from "solid-icons/ai"; import { SelectionProvider, selectable } from "~/features/selectable"; +import { debounce } from "@solid-primitives/scheduled"; import css from "./filetree.module.css"; -import { debounce } from "~/utilities"; selectable; diff --git a/src/features/file/grid.tsx b/src/features/file/grid.tsx index 22c7c26..1deed61 100644 --- a/src/features/file/grid.tsx +++ b/src/features/file/grid.tsx @@ -1,9 +1,10 @@ import { Accessor, Component, createEffect, createMemo, createSignal, JSX } from "solid-js"; -import { debounce, decode, Mutation } from "~/utilities"; +import { decode, Mutation } from "~/utilities"; import { Column, GridApi as GridCompApi, Grid as GridComp } from "~/components/grid"; import { createDataSet, DataSetNode, DataSetRowNode } from "~/components/table"; import { SelectionItem } from "../selectable"; import { useI18n } from "../i18n"; +import { debounce } from "@solid-primitives/scheduled"; import css from "./grid.module.css" export type Entry = { key: string } & { [lang: string]: string }; diff --git a/src/routes/(editor)/experimental/grid.tsx b/src/routes/(editor)/experimental/grid.tsx index bd988fc..037b8e1 100644 --- a/src/routes/(editor)/experimental/grid.tsx +++ b/src/routes/(editor)/experimental/grid.tsx @@ -2,8 +2,9 @@ import { Sidebar } from '~/components/sidebar'; import { CellEditor, Column, DataSetGroupNode, DataSetNode, DataSetRowNode, Grid, GridApi } from '~/components/grid'; import { people, Person } from './experimental.data'; import { Component, createEffect, createMemo, createSignal, For, Match, Switch } from 'solid-js'; -import { debounce, MutarionKind, Mutation } from '~/utilities'; +import { MutarionKind, Mutation } from '~/utilities'; import { createDataSet, Table } from '~/components/table'; +import { debounce } from '@solid-primitives/scheduled'; import css from './grid.module.css'; export default function GridExperiment() { diff --git a/src/utilities.spec.ts b/src/utilities.spec.ts index e2394c4..c456d36 100644 --- a/src/utilities.spec.ts +++ b/src/utilities.spec.ts @@ -72,40 +72,6 @@ describe('utilities', () => { }); }); - describe('debounce', () => { - const { tick } = useFakeTimers(); - - it('should run the given callback after the provided time', async () => { - // Arrange - const callback = mock(() => { }); - const delay = 1000; - const debounced = debounce(callback, delay); - - // Act - debounced(); - tick(delay); - - // Assert - expect(callback).toHaveBeenCalledTimes(1); - }); - - it('should reset if another call is made', async () => { - // Arrange - const callback = mock(() => { }); - const delay = 1000; - const debounced = debounce(callback, delay); - - // Act - debounced(); - tick(delay / 2); - debounced(); - tick(delay); - - // Assert - expect(callback).toHaveBeenCalledTimes(1); - }); - }); - describe('deepCopy', () => { it('can skip values passed by reference (non-objects, null, and undefined)', async () => { // arrange diff --git a/src/utilities.ts b/src/utilities.ts index 9bc9fd5..e58a76d 100644 --- a/src/utilities.ts +++ b/src/utilities.ts @@ -23,18 +23,6 @@ const decodeReplacer = (_: any, char: string) => ({ }[char.charAt(0)] ?? ''); export const decode = (subject: string): string => subject.replace(decodeRegex, decodeReplacer); -export const debounce = void>(callback: T, delay: number): ((...args: Parameters) => void) => { - let handle: ReturnType | undefined; - - return (...args: Parameters) => { - if (handle) { - clearTimeout(handle); - } - - handle = setTimeout(() => callback(...args), delay); - }; -}; - export const deepCopy = (original: T): T => { if (typeof original !== 'object' || original === null || original === undefined) { return original;