remove debounce in favor of solid-primitive
This commit is contained in:
parent
caa35c92e9
commit
7e5af28ac2
7 changed files with 6 additions and 49 deletions
BIN
bun.lockb
BIN
bun.lockb
Binary file not shown.
|
@ -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",
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 = <T extends (...args: any[]) => void>(callback: T, delay: number): ((...args: Parameters<T>) => void) => {
|
||||
let handle: ReturnType<typeof setTimeout> | undefined;
|
||||
|
||||
return (...args: Parameters<T>) => {
|
||||
if (handle) {
|
||||
clearTimeout(handle);
|
||||
}
|
||||
|
||||
handle = setTimeout(() => callback(...args), delay);
|
||||
};
|
||||
};
|
||||
|
||||
export const deepCopy = <T>(original: T): T => {
|
||||
if (typeof original !== 'object' || original === null || original === undefined) {
|
||||
return original;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue