react-state-custom 1.0.12 → 1.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,38 @@
1
+ // Debounce function
2
+ export function debounce<T extends (...args: any[]) => any>(
3
+ func: T,
4
+ wait: number
5
+ ): ((...args: Parameters<T>) => void) & { cancel: any } {
6
+ let timeout: ReturnType<typeof setTimeout> | null = null;
7
+
8
+ let fn: Function & { cancel: any } = function (...args: Parameters<T>): void {
9
+ if (timeout) {
10
+ clearTimeout(timeout);
11
+ }
12
+ timeout = setTimeout(() => {
13
+ func(...args);
14
+ }, wait);
15
+ } as any;
16
+
17
+ fn.cancel = () => clearTimeout(timeout!);
18
+
19
+ return fn as any;
20
+ }
21
+
22
+ // Memoize function
23
+ export function memoize<T extends (...args: any[]) => any>(
24
+ func: T
25
+ ): (...args: Parameters<T>) => ReturnType<T> {
26
+ const cache = new Map<string, ReturnType<T>>();
27
+
28
+ return function (...args: Parameters<T>): ReturnType<T> {
29
+ const key = JSON.stringify(args);
30
+ if (cache.has(key)) {
31
+ return cache.get(key) as ReturnType<T>;
32
+ }
33
+ const result = func(...args);
34
+ cache.set(key, result);
35
+ return result;
36
+ };
37
+ }
38
+
package/vite.config.ts CHANGED
@@ -23,7 +23,7 @@ export default defineConfig({
23
23
  },
24
24
  rollupOptions: {
25
25
  // Ensure to externalize deps that shouldn't be bundled
26
- external: ['react', 'react-dom'],
26
+ external: ['react', 'react-dom', 'react/jsx-runtime', 'react/jsx-dev-runtime'],
27
27
  output: {
28
28
  globals: {
29
29
  'react': 'React',
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
  },
32
32
  },
33
33
  },
34
- sourcemap:true
34
+ sourcemap: true
35
35
  },
36
36
  server: {
37
37
  port: 3000,