Skip to content

Commit a01561a

Browse files
committed
feat: replace lodash-es debounce with custom implementation and remove unused dependencies
1 parent 55ebf28 commit a01561a

File tree

4 files changed

+37
-11
lines changed

4 files changed

+37
-11
lines changed

bun.lock

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222
"@sveltejs/vite-plugin-svelte": "^6.2.0",
2323
"@tailwindcss/typography": "^0.5.18",
2424
"@tailwindcss/vite": "^4.1.13",
25-
"@types/lodash-es": "^4.17.12",
2625
"@types/node": "^24.10.1",
2726
"@types/swagger-ui": "^5.21.1",
2827
"@vitest/browser": "^3.2.4",
2928
"clsx": "^2.1.1",
30-
"lodash-es": "^4.17.21",
3129
"mode-watcher": "^1.1.0",
3230
"openapi-types": "^12.1.3",
3331
"playwright": "^1.55.1",
@@ -364,10 +362,6 @@
364362

365363
"@types/json-schema": ["@types/[email protected]", "", {}, "sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA=="],
366364

367-
"@types/lodash": ["@types/[email protected]", "", {}, "sha512-H3MHACvFUEiujabxhaI/ImO6gUrd8oOurg7LQtS7mbwIXA/cUqWrvBsaeJ23aZEPk1TAYkurjfMbSELfoCXlGA=="],
368-
369-
"@types/lodash-es": ["@types/[email protected]", "", { "dependencies": { "@types/lodash": "*" } }, "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ=="],
370-
371365
"@types/node": ["@types/[email protected]", "", { "dependencies": { "undici-types": "~7.16.0" } }, "sha512-GNWcUTRBgIRJD5zj+Tq0fKOJ5XZajIiBroOF0yvj2bSU1WvNdYS/dn9UxwsujGW4JX06dnHyjV2y9rRaybH0iQ=="],
372366

373367
"@types/ramda": ["@types/[email protected]", "", { "dependencies": { "types-ramda": "^0.30.1" } }, "sha512-PyzHvjCalm2BRYjAU6nIB3TprYwMNOUY/7P/N8bSzp9W/yM2YrtGtAnnVtaCNSeOZ8DzKyFDvaqQs7LnWwwmBA=="],
@@ -684,8 +678,6 @@
684678

685679
"lodash": ["[email protected]", "", {}, "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg=="],
686680

687-
"lodash-es": ["[email protected]", "", {}, "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw=="],
688-
689681
"lodash.debounce": ["[email protected]", "", {}, "sha512-FT1yDzDYEoYWhnSGnpE/4Kj1fLZkDFyqRb7fNt6FdYOSxlUWAtp42Eh6Wb0rGIv/m9Bgo7x4GhQbm5Ys4SG5ow=="],
690682

691683
"lodash.get": ["[email protected]", "", {}, "sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ=="],

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,10 @@
7878
"@sveltejs/vite-plugin-svelte": "^6.2.0",
7979
"@tailwindcss/typography": "^0.5.18",
8080
"@tailwindcss/vite": "^4.1.13",
81-
"@types/lodash-es": "^4.17.12",
8281
"@types/node": "^24.10.1",
8382
"@types/swagger-ui": "^5.21.1",
8483
"@vitest/browser": "^3.2.4",
8584
"clsx": "^2.1.1",
86-
"lodash-es": "^4.17.21",
8785
"mode-watcher": "^1.1.0",
8886
"openapi-types": "^12.1.3",
8987
"playwright": "^1.55.1",

src/lib/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Plugin, ViteDevServer, ResolvedConfig } from 'vite';
22
import type { OpenAPIV3 } from 'openapi-types';
33
import { generateSpec, writeSpec, type GeneratorOptions } from './generator.js';
44
import { resolve } from 'path';
5-
import { debounce } from 'lodash-es';
5+
import { debounce } from './utils.js';
66

77
/**
88
* Plugin options for the OpenAPI generator

src/lib/utils.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/**
2+
* Creates a debounced function that delays invoking `func` until after `wait` milliseconds
3+
* have elapsed since the last time the debounced function was invoked.
4+
*
5+
* @param func The function to debounce.
6+
* @param wait The number of milliseconds to delay.
7+
* @returns A new debounced function with a `cancel` method.
8+
*/
9+
export function debounce<T extends (...args: any[]) => any>(
10+
func: T,
11+
wait: number
12+
): ((...args: Parameters<T>) => void) & { cancel: () => void } {
13+
let timeoutId: ReturnType<typeof setTimeout> | null = null;
14+
15+
function debounced(this: any, ...args: Parameters<T>) {
16+
const context = this;
17+
18+
if (timeoutId) {
19+
clearTimeout(timeoutId);
20+
}
21+
22+
timeoutId = setTimeout(() => {
23+
func.apply(context, args);
24+
timeoutId = null;
25+
}, wait);
26+
}
27+
28+
debounced.cancel = () => {
29+
if (timeoutId) {
30+
clearTimeout(timeoutId);
31+
timeoutId = null;
32+
}
33+
};
34+
35+
return debounced as ((...args: Parameters<T>) => void) & { cancel: () => void };
36+
}

0 commit comments

Comments
 (0)