@tanstack/solid-pacer 0.2.0
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.
- package/LICENSE +21 -0
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +32 -0
- package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -0
- package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +42 -0
- package/dist/cjs/async-debouncer/index.cjs +12 -0
- package/dist/cjs/async-debouncer/index.cjs.map +1 -0
- package/dist/cjs/async-debouncer/index.d.cts +2 -0
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs +69 -0
- package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -0
- package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +90 -0
- package/dist/cjs/async-queuer/index.cjs +12 -0
- package/dist/cjs/async-queuer/index.cjs.map +1 -0
- package/dist/cjs/async-queuer/index.d.cts +2 -0
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +50 -0
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -0
- package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +46 -0
- package/dist/cjs/async-rate-limiter/index.cjs +12 -0
- package/dist/cjs/async-rate-limiter/index.cjs.map +1 -0
- package/dist/cjs/async-rate-limiter/index.d.cts +2 -0
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs +42 -0
- package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -0
- package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +46 -0
- package/dist/cjs/async-throttler/index.cjs +12 -0
- package/dist/cjs/async-throttler/index.cjs.map +1 -0
- package/dist/cjs/async-throttler/index.d.cts +2 -0
- package/dist/cjs/compare/index.cjs +10 -0
- package/dist/cjs/compare/index.cjs.map +1 -0
- package/dist/cjs/compare/index.d.cts +1 -0
- package/dist/cjs/debouncer/createDebouncedSignal.cjs +11 -0
- package/dist/cjs/debouncer/createDebouncedSignal.cjs.map +1 -0
- package/dist/cjs/debouncer/createDebouncedSignal.d.cts +47 -0
- package/dist/cjs/debouncer/createDebouncedValue.cjs +19 -0
- package/dist/cjs/debouncer/createDebouncedValue.cjs.map +1 -0
- package/dist/cjs/debouncer/createDebouncedValue.d.cts +44 -0
- package/dist/cjs/debouncer/createDebouncer.cjs +32 -0
- package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -0
- package/dist/cjs/debouncer/createDebouncer.d.cts +47 -0
- package/dist/cjs/debouncer/index.cjs +16 -0
- package/dist/cjs/debouncer/index.cjs.map +1 -0
- package/dist/cjs/debouncer/index.d.cts +4 -0
- package/dist/cjs/index.cjs +38 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +18 -0
- package/dist/cjs/queuer/createQueuer.cjs +66 -0
- package/dist/cjs/queuer/createQueuer.cjs.map +1 -0
- package/dist/cjs/queuer/createQueuer.d.cts +82 -0
- package/dist/cjs/queuer/index.cjs +12 -0
- package/dist/cjs/queuer/index.cjs.map +1 -0
- package/dist/cjs/queuer/index.d.cts +2 -0
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs +15 -0
- package/dist/cjs/rate-limiter/createRateLimitedSignal.cjs.map +1 -0
- package/dist/cjs/rate-limiter/createRateLimitedSignal.d.cts +58 -0
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs +13 -0
- package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -0
- package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +51 -0
- package/dist/cjs/rate-limiter/createRateLimiter.cjs +50 -0
- package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -0
- package/dist/cjs/rate-limiter/createRateLimiter.d.cts +49 -0
- package/dist/cjs/rate-limiter/index.cjs +16 -0
- package/dist/cjs/rate-limiter/index.cjs.map +1 -0
- package/dist/cjs/rate-limiter/index.d.cts +4 -0
- package/dist/cjs/throttler/createThrottledSignal.cjs +11 -0
- package/dist/cjs/throttler/createThrottledSignal.cjs.map +1 -0
- package/dist/cjs/throttler/createThrottledSignal.d.cts +42 -0
- package/dist/cjs/throttler/createThrottledValue.cjs +19 -0
- package/dist/cjs/throttler/createThrottledValue.cjs.map +1 -0
- package/dist/cjs/throttler/createThrottledValue.d.cts +36 -0
- package/dist/cjs/throttler/createThrottler.cjs +42 -0
- package/dist/cjs/throttler/createThrottler.cjs.map +1 -0
- package/dist/cjs/throttler/createThrottler.d.cts +47 -0
- package/dist/cjs/throttler/index.cjs +16 -0
- package/dist/cjs/throttler/index.cjs.map +1 -0
- package/dist/cjs/throttler/index.d.cts +4 -0
- package/dist/cjs/types/index.cjs +10 -0
- package/dist/cjs/types/index.cjs.map +1 -0
- package/dist/cjs/types/index.d.cts +1 -0
- package/dist/cjs/utils/index.cjs +10 -0
- package/dist/cjs/utils/index.cjs.map +1 -0
- package/dist/cjs/utils/index.d.cts +1 -0
- package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +42 -0
- package/dist/esm/async-debouncer/createAsyncDebouncer.js +32 -0
- package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -0
- package/dist/esm/async-debouncer/index.d.ts +2 -0
- package/dist/esm/async-debouncer/index.js +6 -0
- package/dist/esm/async-debouncer/index.js.map +1 -0
- package/dist/esm/async-queuer/createAsyncQueuer.d.ts +90 -0
- package/dist/esm/async-queuer/createAsyncQueuer.js +69 -0
- package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -0
- package/dist/esm/async-queuer/index.d.ts +2 -0
- package/dist/esm/async-queuer/index.js +6 -0
- package/dist/esm/async-queuer/index.js.map +1 -0
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +46 -0
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +50 -0
- package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -0
- package/dist/esm/async-rate-limiter/index.d.ts +2 -0
- package/dist/esm/async-rate-limiter/index.js +6 -0
- package/dist/esm/async-rate-limiter/index.js.map +1 -0
- package/dist/esm/async-throttler/createAsyncThrottler.d.ts +46 -0
- package/dist/esm/async-throttler/createAsyncThrottler.js +42 -0
- package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -0
- package/dist/esm/async-throttler/index.d.ts +2 -0
- package/dist/esm/async-throttler/index.js +6 -0
- package/dist/esm/async-throttler/index.js.map +1 -0
- package/dist/esm/compare/index.d.ts +1 -0
- package/dist/esm/compare/index.js +2 -0
- package/dist/esm/compare/index.js.map +1 -0
- package/dist/esm/debouncer/createDebouncedSignal.d.ts +47 -0
- package/dist/esm/debouncer/createDebouncedSignal.js +11 -0
- package/dist/esm/debouncer/createDebouncedSignal.js.map +1 -0
- package/dist/esm/debouncer/createDebouncedValue.d.ts +44 -0
- package/dist/esm/debouncer/createDebouncedValue.js +19 -0
- package/dist/esm/debouncer/createDebouncedValue.js.map +1 -0
- package/dist/esm/debouncer/createDebouncer.d.ts +47 -0
- package/dist/esm/debouncer/createDebouncer.js +32 -0
- package/dist/esm/debouncer/createDebouncer.js.map +1 -0
- package/dist/esm/debouncer/index.d.ts +4 -0
- package/dist/esm/debouncer/index.js +10 -0
- package/dist/esm/debouncer/index.js.map +1 -0
- package/dist/esm/index.d.ts +18 -0
- package/dist/esm/index.js +32 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/queuer/createQueuer.d.ts +82 -0
- package/dist/esm/queuer/createQueuer.js +66 -0
- package/dist/esm/queuer/createQueuer.js.map +1 -0
- package/dist/esm/queuer/index.d.ts +2 -0
- package/dist/esm/queuer/index.js +6 -0
- package/dist/esm/queuer/index.js.map +1 -0
- package/dist/esm/rate-limiter/createRateLimitedSignal.d.ts +58 -0
- package/dist/esm/rate-limiter/createRateLimitedSignal.js +15 -0
- package/dist/esm/rate-limiter/createRateLimitedSignal.js.map +1 -0
- package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +51 -0
- package/dist/esm/rate-limiter/createRateLimitedValue.js +13 -0
- package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -0
- package/dist/esm/rate-limiter/createRateLimiter.d.ts +49 -0
- package/dist/esm/rate-limiter/createRateLimiter.js +50 -0
- package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -0
- package/dist/esm/rate-limiter/index.d.ts +4 -0
- package/dist/esm/rate-limiter/index.js +10 -0
- package/dist/esm/rate-limiter/index.js.map +1 -0
- package/dist/esm/throttler/createThrottledSignal.d.ts +42 -0
- package/dist/esm/throttler/createThrottledSignal.js +11 -0
- package/dist/esm/throttler/createThrottledSignal.js.map +1 -0
- package/dist/esm/throttler/createThrottledValue.d.ts +36 -0
- package/dist/esm/throttler/createThrottledValue.js +19 -0
- package/dist/esm/throttler/createThrottledValue.js.map +1 -0
- package/dist/esm/throttler/createThrottler.d.ts +47 -0
- package/dist/esm/throttler/createThrottler.js +42 -0
- package/dist/esm/throttler/createThrottler.js.map +1 -0
- package/dist/esm/throttler/index.d.ts +4 -0
- package/dist/esm/throttler/index.js +10 -0
- package/dist/esm/throttler/index.js.map +1 -0
- package/dist/esm/types/index.d.ts +1 -0
- package/dist/esm/types/index.js +2 -0
- package/dist/esm/types/index.js.map +1 -0
- package/dist/esm/utils/index.d.ts +1 -0
- package/dist/esm/utils/index.js +2 -0
- package/dist/esm/utils/index.js.map +1 -0
- package/package.json +163 -0
- package/src/async-debouncer/createAsyncDebouncer.ts +89 -0
- package/src/async-debouncer/index.ts +4 -0
- package/src/async-queuer/createAsyncQueuer.ts +175 -0
- package/src/async-queuer/index.ts +3 -0
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +116 -0
- package/src/async-rate-limiter/index.ts +4 -0
- package/src/async-throttler/createAsyncThrottler.ts +106 -0
- package/src/async-throttler/index.ts +4 -0
- package/src/compare/index.ts +1 -0
- package/src/debouncer/createDebouncedSignal.ts +59 -0
- package/src/debouncer/createDebouncedValue.ts +64 -0
- package/src/debouncer/createDebouncer.ts +90 -0
- package/src/debouncer/index.ts +6 -0
- package/src/index.ts +36 -0
- package/src/queuer/createQueuer.ts +167 -0
- package/src/queuer/index.ts +3 -0
- package/src/rate-limiter/createRateLimitedSignal.ts +74 -0
- package/src/rate-limiter/createRateLimitedValue.ts +66 -0
- package/src/rate-limiter/createRateLimiter.ts +115 -0
- package/src/rate-limiter/index.ts +5 -0
- package/src/throttler/createThrottledSignal.ts +52 -0
- package/src/throttler/createThrottledValue.ts +56 -0
- package/src/throttler/createThrottler.ts +106 -0
- package/src/throttler/index.ts +6 -0
- package/src/types/index.ts +1 -0
- package/src/utils/index.ts +1 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { SolidDebouncer } from './createDebouncer.cjs';
|
|
2
|
+
import { Accessor, Setter } from 'solid-js';
|
|
3
|
+
import { DebouncerOptions } from '@tanstack/pacer/debouncer';
|
|
4
|
+
/**
|
|
5
|
+
* A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.
|
|
6
|
+
* This hook provides both the current debounced value and methods to update it.
|
|
7
|
+
*
|
|
8
|
+
* The state value is only updated after the specified wait time has elapsed since the last update attempt.
|
|
9
|
+
* If another update is attempted before the wait time expires, the timer resets and starts waiting again.
|
|
10
|
+
* This is useful for handling frequent state updates that should be throttled, like search input values
|
|
11
|
+
* or window resize dimensions.
|
|
12
|
+
*
|
|
13
|
+
* The hook returns a tuple containing:
|
|
14
|
+
* - The current debounced value accessor
|
|
15
|
+
* - A function to update the debounced value
|
|
16
|
+
* - The debouncer instance with additional control methods and state signals
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```tsx
|
|
20
|
+
* // Debounced search input
|
|
21
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
|
|
22
|
+
* wait: 500 // Wait 500ms after last keystroke
|
|
23
|
+
* });
|
|
24
|
+
*
|
|
25
|
+
* // Update value - will be debounced
|
|
26
|
+
* const handleChange = (e) => {
|
|
27
|
+
* setSearchTerm(e.target.value);
|
|
28
|
+
* };
|
|
29
|
+
*
|
|
30
|
+
* // Access debouncer state via signals
|
|
31
|
+
* console.log('Executions:', debouncer.executionCount());
|
|
32
|
+
* console.log('Is pending:', debouncer.isPending());
|
|
33
|
+
*
|
|
34
|
+
* // In onExecute callback, use get* methods
|
|
35
|
+
* const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
|
|
36
|
+
* wait: 500,
|
|
37
|
+
* onExecute: (debouncer) => {
|
|
38
|
+
* console.log('Total executions:', debouncer.getExecutionCount());
|
|
39
|
+
* }
|
|
40
|
+
* });
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
export declare function createDebouncedSignal<TValue>(value: TValue, initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>): [
|
|
44
|
+
Accessor<TValue>,
|
|
45
|
+
Setter<TValue>,
|
|
46
|
+
SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>
|
|
47
|
+
];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const solidJs = require("solid-js");
|
|
4
|
+
const createDebouncedSignal = require("./createDebouncedSignal.cjs");
|
|
5
|
+
function createDebouncedValue(value, initialOptions) {
|
|
6
|
+
const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal.createDebouncedSignal(
|
|
7
|
+
value(),
|
|
8
|
+
initialOptions
|
|
9
|
+
);
|
|
10
|
+
solidJs.createEffect(() => {
|
|
11
|
+
setDebouncedValue(value());
|
|
12
|
+
solidJs.onCleanup(() => {
|
|
13
|
+
debouncer.cancel();
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
return [debouncedValue, debouncer];
|
|
17
|
+
}
|
|
18
|
+
exports.createDebouncedValue = createDebouncedValue;
|
|
19
|
+
//# sourceMappingURL=createDebouncedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDebouncedValue.cjs","sources":["../../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced value that updates only after a specified delay.\n * Unlike createDebouncedSignal, this hook automatically tracks changes to the input value\n * and updates the debounced value accordingly.\n *\n * The debounced value will only update after the specified wait time has elapsed since\n * the last change to the input value. If the input value changes again before the wait\n * time expires, the timer resets and starts waiting again.\n *\n * This is useful for deriving debounced values from props or state that change frequently,\n * like search queries or form inputs, where you want to limit how often downstream effects\n * or calculations occur.\n *\n * The hook returns a tuple containing:\n * - The current debounced value (as an Accessor)\n * - The debouncer instance with control methods and state signals\n *\n * @example\n * ```tsx\n * // Debounce a search query\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // debouncedQuery will update 500ms after searchQuery stops changing\n * createEffect(() => {\n * fetchSearchResults(debouncedQuery());\n * });\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Handle input changes\n * const handleChange = (e) => {\n * setSearchQuery(e.target.value);\n * };\n * ```\n */\nexport function createDebouncedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n onCleanup(() => {\n debouncer.cancel()\n })\n })\n\n return [debouncedValue, debouncer]\n}\n"],"names":["createDebouncedSignal","createEffect","onCleanup"],"mappings":";;;;AA8CgB,SAAA,qBACd,OACA,gBACwE;AACxE,QAAM,CAAC,gBAAgB,mBAAmB,SAAS,IAAIA,sBAAA;AAAA,IACrD,MAAM;AAAA,IACN;AAAA,EACF;AAEAC,UAAAA,aAAa,MAAM;AACjB,sBAAkB,OAAc;AAChCC,YAAAA,UAAU,MAAM;AACd,gBAAU,OAAO;AAAA,IAAA,CAClB;AAAA,EAAA,CACF;AAEM,SAAA,CAAC,gBAAgB,SAAS;AACnC;;"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { SolidDebouncer } from './createDebouncer.cjs';
|
|
2
|
+
import { Accessor, Setter } from 'solid-js';
|
|
3
|
+
import { DebouncerOptions } from '@tanstack/pacer/debouncer';
|
|
4
|
+
/**
|
|
5
|
+
* A Solid hook that creates a debounced value that updates only after a specified delay.
|
|
6
|
+
* Unlike createDebouncedSignal, this hook automatically tracks changes to the input value
|
|
7
|
+
* and updates the debounced value accordingly.
|
|
8
|
+
*
|
|
9
|
+
* The debounced value will only update after the specified wait time has elapsed since
|
|
10
|
+
* the last change to the input value. If the input value changes again before the wait
|
|
11
|
+
* time expires, the timer resets and starts waiting again.
|
|
12
|
+
*
|
|
13
|
+
* This is useful for deriving debounced values from props or state that change frequently,
|
|
14
|
+
* like search queries or form inputs, where you want to limit how often downstream effects
|
|
15
|
+
* or calculations occur.
|
|
16
|
+
*
|
|
17
|
+
* The hook returns a tuple containing:
|
|
18
|
+
* - The current debounced value (as an Accessor)
|
|
19
|
+
* - The debouncer instance with control methods and state signals
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* // Debounce a search query
|
|
24
|
+
* const [searchQuery, setSearchQuery] = createSignal('');
|
|
25
|
+
* const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {
|
|
26
|
+
* wait: 500 // Wait 500ms after last change
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // debouncedQuery will update 500ms after searchQuery stops changing
|
|
30
|
+
* createEffect(() => {
|
|
31
|
+
* fetchSearchResults(debouncedQuery());
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // Access debouncer state via signals
|
|
35
|
+
* console.log('Executions:', debouncer.executionCount());
|
|
36
|
+
* console.log('Is pending:', debouncer.isPending());
|
|
37
|
+
*
|
|
38
|
+
* // Handle input changes
|
|
39
|
+
* const handleChange = (e) => {
|
|
40
|
+
* setSearchQuery(e.target.value);
|
|
41
|
+
* };
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare function createDebouncedValue<TValue>(value: Accessor<TValue>, initialOptions: DebouncerOptions<Setter<TValue>, [Accessor<TValue>]>): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, [Accessor<TValue>]>];
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const debouncer = require("@tanstack/pacer/debouncer");
|
|
4
|
+
const solidJs = require("solid-js");
|
|
5
|
+
const utils = require("@tanstack/pacer/utils");
|
|
6
|
+
function createDebouncer(fn, initialOptions) {
|
|
7
|
+
const debouncer$1 = new debouncer.Debouncer(fn, initialOptions);
|
|
8
|
+
const [executionCount, setExecutionCount] = solidJs.createSignal(
|
|
9
|
+
debouncer$1.getExecutionCount()
|
|
10
|
+
);
|
|
11
|
+
const [isPending, setIsPending] = solidJs.createSignal(debouncer$1.getIsPending());
|
|
12
|
+
function setOptions(newOptions) {
|
|
13
|
+
debouncer$1.setOptions({
|
|
14
|
+
...newOptions,
|
|
15
|
+
onExecute: (debouncer2) => {
|
|
16
|
+
setExecutionCount(debouncer2.getExecutionCount());
|
|
17
|
+
setIsPending(debouncer2.getIsPending());
|
|
18
|
+
const onExecute = newOptions.onExecute ?? initialOptions.onExecute;
|
|
19
|
+
onExecute == null ? void 0 : onExecute(debouncer2);
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
setOptions(initialOptions);
|
|
24
|
+
return {
|
|
25
|
+
...utils.bindInstanceMethods(debouncer$1),
|
|
26
|
+
executionCount,
|
|
27
|
+
isPending,
|
|
28
|
+
setOptions
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
exports.createDebouncer = createDebouncer;
|
|
32
|
+
//# sourceMappingURL=createDebouncer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createDebouncer.cjs","sources":["../../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type { DebouncerOptions } from '@tanstack/pacer/debouncer'\n\n/**\n * An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer\n */\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n> extends Omit<Debouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {\n executionCount: Accessor<number>\n isPending: Accessor<boolean>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * @example\n * ```tsx\n * // Debounce a search function to limit API calls\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 } // Wait 500ms after last keystroke\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.executionCount());\n * console.log('Is pending:', debouncer.isPending());\n *\n * // Update options\n * debouncer.setOptions({ wait: 1000 });\n * ```\n */\nexport function createDebouncer<\n TFn extends AnyFunction,\n TArgs extends Parameters<TFn>,\n>(\n fn: TFn,\n initialOptions: DebouncerOptions<TFn, TArgs>,\n): SolidDebouncer<TFn, TArgs> {\n const debouncer = new Debouncer<TFn, TArgs>(fn, initialOptions)\n\n const [executionCount, setExecutionCount] = createSignal(\n debouncer.getExecutionCount(),\n )\n const [isPending, setIsPending] = createSignal(debouncer.getIsPending())\n\n function setOptions(newOptions: Partial<DebouncerOptions<TFn, TArgs>>) {\n debouncer.setOptions({\n ...newOptions,\n onExecute: (debouncer) => {\n setExecutionCount(debouncer.getExecutionCount())\n setIsPending(debouncer.getIsPending())\n\n const onExecute = newOptions.onExecute ?? initialOptions.onExecute\n onExecute?.(debouncer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(debouncer),\n executionCount,\n isPending,\n setOptions,\n }\n}\n"],"names":["debouncer","Debouncer","createSignal","bindInstanceMethods"],"mappings":";;;;;AAsDgB,SAAA,gBAId,IACA,gBAC4B;AAC5B,QAAMA,cAAY,IAAIC,oBAAsB,IAAI,cAAc;AAExD,QAAA,CAAC,gBAAgB,iBAAiB,IAAIC,QAAA;AAAA,IAC1CF,YAAU,kBAAkB;AAAA,EAC9B;AACA,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,YAAU,cAAc;AAEvE,WAAS,WAAW,YAAmD;AACrEA,gBAAU,WAAW;AAAA,MACnB,GAAG;AAAA,MACH,WAAW,CAACA,eAAc;AACNA,0BAAAA,WAAU,mBAAmB;AAClCA,qBAAAA,WAAU,cAAc;AAE/B,cAAA,YAAY,WAAW,aAAa,eAAe;AACzD,+CAAYA;AAAAA,MAAS;AAAA,IACvB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,WAAS;AAAA,IAChC;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Debouncer, DebouncerOptions } from '@tanstack/pacer/debouncer';
|
|
2
|
+
import { Accessor } from 'solid-js';
|
|
3
|
+
import { AnyFunction } from '@tanstack/pacer/types';
|
|
4
|
+
/**
|
|
5
|
+
* An extension of the Debouncer class that adds Solid signals to access the internal state of the debouncer
|
|
6
|
+
*/
|
|
7
|
+
export interface SolidDebouncer<TFn extends AnyFunction, TArgs extends Parameters<TFn>> extends Omit<Debouncer<TFn, TArgs>, 'getExecutionCount' | 'getIsPending'> {
|
|
8
|
+
executionCount: Accessor<number>;
|
|
9
|
+
isPending: Accessor<boolean>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* A Solid hook that creates and manages a Debouncer instance.
|
|
13
|
+
*
|
|
14
|
+
* This is a lower-level hook that provides direct access to the Debouncer's functionality without
|
|
15
|
+
* any built-in state management. This allows you to integrate it with any state management solution
|
|
16
|
+
* you prefer (createSignal, Redux, Zustand, etc.).
|
|
17
|
+
*
|
|
18
|
+
* This hook provides debouncing functionality to limit how often a function can be called,
|
|
19
|
+
* waiting for a specified delay before executing the latest call. This is useful for handling
|
|
20
|
+
* frequent events like window resizing, scroll events, or real-time search inputs.
|
|
21
|
+
*
|
|
22
|
+
* The debouncer will only execute the function after the specified wait time has elapsed
|
|
23
|
+
* since the last call. If the function is called again before the wait time expires, the
|
|
24
|
+
* timer resets and starts waiting again.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* // Debounce a search function to limit API calls
|
|
29
|
+
* const debouncer = createDebouncer(
|
|
30
|
+
* (query: string) => fetchSearchResults(query),
|
|
31
|
+
* { wait: 500 } // Wait 500ms after last keystroke
|
|
32
|
+
* );
|
|
33
|
+
*
|
|
34
|
+
* // In an event handler
|
|
35
|
+
* const handleChange = (e) => {
|
|
36
|
+
* debouncer.maybeExecute(e.target.value);
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* // Access debouncer state via signals
|
|
40
|
+
* console.log('Executions:', debouncer.executionCount());
|
|
41
|
+
* console.log('Is pending:', debouncer.isPending());
|
|
42
|
+
*
|
|
43
|
+
* // Update options
|
|
44
|
+
* debouncer.setOptions({ wait: 1000 });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export declare function createDebouncer<TFn extends AnyFunction, TArgs extends Parameters<TFn>>(fn: TFn, initialOptions: DebouncerOptions<TFn, TArgs>): SolidDebouncer<TFn, TArgs>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const debouncer = require("@tanstack/pacer/debouncer");
|
|
4
|
+
const createDebouncedSignal = require("./createDebouncedSignal.cjs");
|
|
5
|
+
const createDebouncedValue = require("./createDebouncedValue.cjs");
|
|
6
|
+
const createDebouncer = require("./createDebouncer.cjs");
|
|
7
|
+
exports.createDebouncedSignal = createDebouncedSignal.createDebouncedSignal;
|
|
8
|
+
exports.createDebouncedValue = createDebouncedValue.createDebouncedValue;
|
|
9
|
+
exports.createDebouncer = createDebouncer.createDebouncer;
|
|
10
|
+
Object.keys(debouncer).forEach((k) => {
|
|
11
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: () => debouncer[k]
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const pacer = require("@tanstack/pacer");
|
|
4
|
+
const createAsyncDebouncer = require("./async-debouncer/createAsyncDebouncer.cjs");
|
|
5
|
+
const createAsyncQueuer = require("./async-queuer/createAsyncQueuer.cjs");
|
|
6
|
+
const createAsyncRateLimiter = require("./async-rate-limiter/createAsyncRateLimiter.cjs");
|
|
7
|
+
const createAsyncThrottler = require("./async-throttler/createAsyncThrottler.cjs");
|
|
8
|
+
const createDebouncedSignal = require("./debouncer/createDebouncedSignal.cjs");
|
|
9
|
+
const createDebouncedValue = require("./debouncer/createDebouncedValue.cjs");
|
|
10
|
+
const createDebouncer = require("./debouncer/createDebouncer.cjs");
|
|
11
|
+
const createQueuer = require("./queuer/createQueuer.cjs");
|
|
12
|
+
const createRateLimiter = require("./rate-limiter/createRateLimiter.cjs");
|
|
13
|
+
const createRateLimitedSignal = require("./rate-limiter/createRateLimitedSignal.cjs");
|
|
14
|
+
const createRateLimitedValue = require("./rate-limiter/createRateLimitedValue.cjs");
|
|
15
|
+
const createThrottledSignal = require("./throttler/createThrottledSignal.cjs");
|
|
16
|
+
const createThrottledValue = require("./throttler/createThrottledValue.cjs");
|
|
17
|
+
const createThrottler = require("./throttler/createThrottler.cjs");
|
|
18
|
+
exports.createAsyncDebouncer = createAsyncDebouncer.createAsyncDebouncer;
|
|
19
|
+
exports.createAsyncQueuer = createAsyncQueuer.createAsyncQueuer;
|
|
20
|
+
exports.createAsyncRateLimiter = createAsyncRateLimiter.createAsyncRateLimiter;
|
|
21
|
+
exports.createAsyncThrottler = createAsyncThrottler.createAsyncThrottler;
|
|
22
|
+
exports.createDebouncedSignal = createDebouncedSignal.createDebouncedSignal;
|
|
23
|
+
exports.createDebouncedValue = createDebouncedValue.createDebouncedValue;
|
|
24
|
+
exports.createDebouncer = createDebouncer.createDebouncer;
|
|
25
|
+
exports.createQueuer = createQueuer.createQueuer;
|
|
26
|
+
exports.createRateLimiter = createRateLimiter.createRateLimiter;
|
|
27
|
+
exports.createRateLimitedSignal = createRateLimitedSignal.createRateLimitedSignal;
|
|
28
|
+
exports.createRateLimitedValue = createRateLimitedValue.createRateLimitedValue;
|
|
29
|
+
exports.createThrottledSignal = createThrottledSignal.createThrottledSignal;
|
|
30
|
+
exports.createThrottledValue = createThrottledValue.createThrottledValue;
|
|
31
|
+
exports.createThrottler = createThrottler.createThrottler;
|
|
32
|
+
Object.keys(pacer).forEach((k) => {
|
|
33
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
34
|
+
enumerable: true,
|
|
35
|
+
get: () => pacer[k]
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export * from '@tanstack/pacer';
|
|
2
|
+
/**
|
|
3
|
+
* Export every hook individually - DON'T export from barrel files
|
|
4
|
+
*/
|
|
5
|
+
export * from './async-debouncer/createAsyncDebouncer.cjs';
|
|
6
|
+
export * from './async-queuer/createAsyncQueuer.cjs';
|
|
7
|
+
export * from './async-rate-limiter/createAsyncRateLimiter.cjs';
|
|
8
|
+
export * from './async-throttler/createAsyncThrottler.cjs';
|
|
9
|
+
export * from './debouncer/createDebouncedSignal.cjs';
|
|
10
|
+
export * from './debouncer/createDebouncedValue.cjs';
|
|
11
|
+
export * from './debouncer/createDebouncer.cjs';
|
|
12
|
+
export * from './queuer/createQueuer.cjs';
|
|
13
|
+
export * from './rate-limiter/createRateLimiter.cjs';
|
|
14
|
+
export * from './rate-limiter/createRateLimitedSignal.cjs';
|
|
15
|
+
export * from './rate-limiter/createRateLimitedValue.cjs';
|
|
16
|
+
export * from './throttler/createThrottledSignal.cjs';
|
|
17
|
+
export * from './throttler/createThrottledValue.cjs';
|
|
18
|
+
export * from './throttler/createThrottler.cjs';
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const queuer = require("@tanstack/pacer/queuer");
|
|
4
|
+
const solidJs = require("solid-js");
|
|
5
|
+
const utils = require("@tanstack/pacer/utils");
|
|
6
|
+
function createQueuer(initialOptions = {}) {
|
|
7
|
+
const queuer$1 = new queuer.Queuer(initialOptions);
|
|
8
|
+
const [allItems, setAllItems] = solidJs.createSignal(
|
|
9
|
+
queuer$1.getAllItems()
|
|
10
|
+
);
|
|
11
|
+
const [executionCount, setExecutionCount] = solidJs.createSignal(
|
|
12
|
+
queuer$1.getExecutionCount()
|
|
13
|
+
);
|
|
14
|
+
const [rejectionCount, setRejectionCount] = solidJs.createSignal(
|
|
15
|
+
queuer$1.getRejectionCount()
|
|
16
|
+
);
|
|
17
|
+
const [isEmpty, setIsEmpty] = solidJs.createSignal(queuer$1.getIsEmpty());
|
|
18
|
+
const [isFull, setIsFull] = solidJs.createSignal(queuer$1.getIsFull());
|
|
19
|
+
const [isIdle, setIsIdle] = solidJs.createSignal(queuer$1.getIsIdle());
|
|
20
|
+
const [isRunning, setIsRunning] = solidJs.createSignal(queuer$1.getIsRunning());
|
|
21
|
+
const [peek, setPeek] = solidJs.createSignal(queuer$1.getPeek());
|
|
22
|
+
const [size, setSize] = solidJs.createSignal(queuer$1.getSize());
|
|
23
|
+
function setOptions(newOptions) {
|
|
24
|
+
queuer$1.setOptions({
|
|
25
|
+
...newOptions,
|
|
26
|
+
onItemsChange: (queuer2) => {
|
|
27
|
+
setAllItems(queuer2.getAllItems());
|
|
28
|
+
setExecutionCount(queuer2.getExecutionCount());
|
|
29
|
+
setIsEmpty(queuer2.getIsEmpty());
|
|
30
|
+
setIsFull(queuer2.getIsFull());
|
|
31
|
+
setIsIdle(queuer2.getIsIdle());
|
|
32
|
+
setPeek(() => queuer2.getPeek());
|
|
33
|
+
setSize(queuer2.getSize());
|
|
34
|
+
const onItemsChange = newOptions.onItemsChange ?? initialOptions.onItemsChange;
|
|
35
|
+
onItemsChange == null ? void 0 : onItemsChange(queuer2);
|
|
36
|
+
},
|
|
37
|
+
onIsRunningChange: (queuer2) => {
|
|
38
|
+
setIsRunning(queuer2.getIsRunning());
|
|
39
|
+
setIsIdle(queuer2.getIsIdle());
|
|
40
|
+
const onIsRunningChange = newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange;
|
|
41
|
+
onIsRunningChange == null ? void 0 : onIsRunningChange(queuer2);
|
|
42
|
+
},
|
|
43
|
+
onReject: (item, queuer2) => {
|
|
44
|
+
setRejectionCount(queuer2.getRejectionCount());
|
|
45
|
+
const onReject = newOptions.onReject ?? initialOptions.onReject;
|
|
46
|
+
onReject == null ? void 0 : onReject(item, queuer2);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
setOptions(initialOptions);
|
|
51
|
+
return {
|
|
52
|
+
...utils.bindInstanceMethods(queuer$1),
|
|
53
|
+
allItems,
|
|
54
|
+
executionCount,
|
|
55
|
+
isEmpty,
|
|
56
|
+
isFull,
|
|
57
|
+
isIdle,
|
|
58
|
+
isRunning,
|
|
59
|
+
peek,
|
|
60
|
+
rejectionCount,
|
|
61
|
+
size,
|
|
62
|
+
setOptions
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
exports.createQueuer = createQueuer;
|
|
66
|
+
//# sourceMappingURL=createQueuer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createQueuer.cjs","sources":["../../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { createSignal } from 'solid-js'\nimport { bindInstanceMethods } from '@tanstack/pacer/utils'\nimport type { Accessor } from 'solid-js'\nimport type { QueuerOptions } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue>\n extends Omit<\n Queuer<TValue>,\n | 'getAllItems'\n | 'getExecutionCount'\n | 'getIsEmpty'\n | 'getIsFull'\n | 'getIsIdle'\n | 'getIsRunning'\n | 'getPeek'\n | 'getSize'\n > {\n /**\n * Signal version of `getAllItems`\n */\n allItems: Accessor<Array<TValue>>\n /**\n * Signal version of `getExecutionCount`\n */\n executionCount: Accessor<number>\n /**\n * Signal version of `getIsEmpty`\n */\n isEmpty: Accessor<boolean>\n /**\n * Signal version of `getIsFull`\n */\n isFull: Accessor<boolean>\n /**\n * Signal version of `getIsIdle`\n */\n isIdle: Accessor<boolean>\n /**\n * Signal version of `getIsRunning`\n */\n isRunning: Accessor<boolean>\n /**\n * Signal version of `getPeek`\n */\n peek: Accessor<TValue | undefined>\n /**\n * Signal version of `getSize`\n */\n size: Accessor<number>\n}\n\n/**\n * A Solid hook that creates and manages a Queuer instance.\n *\n * This is a lower-level hook that provides direct access to the Queuer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.\n *\n * For a hook with built-in state management, see createQueuerSignal.\n *\n * The Queuer extends the base Queue to add processing capabilities. Items are processed\n * synchronously in order, with optional delays between processing each item. The queuer includes\n * an internal tick mechanism that can be started and stopped, making it useful as a scheduler.\n * When started, it will process one item per tick, with an optional wait time between ticks.\n *\n * By default uses FIFO (First In First Out) behavior, but can be configured for LIFO\n * (Last In First Out) by specifying 'front' position when adding items.\n *\n * @example\n * ```tsx\n * // Example with custom state management and scheduling\n * const [items, setItems] = createSignal([]);\n *\n * const queue = createQueuer({\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * onItemsChange: (queue) => setItems(queue.getAllItems()),\n * getPriority: (item) => item.priority // Process higher priority items first\n * });\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access queue state via signals\n * console.log('Items:', queue.allItems());\n * console.log('Size:', queue.size());\n * console.log('Is empty:', queue.isEmpty());\n * console.log('Is running:', queue.isRunning());\n * console.log('Next item:', queue.peek());\n * ```\n */\nexport function createQueuer<TValue>(\n initialOptions: QueuerOptions<TValue> = {},\n): SolidQueuer<TValue> {\n const queuer = new Queuer<TValue>(initialOptions)\n\n const [allItems, setAllItems] = createSignal<Array<TValue>>(\n queuer.getAllItems(),\n )\n const [executionCount, setExecutionCount] = createSignal(\n queuer.getExecutionCount(),\n )\n const [rejectionCount, setRejectionCount] = createSignal(\n queuer.getRejectionCount(),\n )\n const [isEmpty, setIsEmpty] = createSignal(queuer.getIsEmpty())\n const [isFull, setIsFull] = createSignal(queuer.getIsFull())\n const [isIdle, setIsIdle] = createSignal(queuer.getIsIdle())\n const [isRunning, setIsRunning] = createSignal(queuer.getIsRunning())\n const [peek, setPeek] = createSignal<TValue | undefined>(queuer.getPeek())\n const [size, setSize] = createSignal(queuer.getSize())\n\n function setOptions(newOptions: Partial<QueuerOptions<TValue>>) {\n queuer.setOptions({\n ...newOptions,\n onItemsChange: (queuer) => {\n setAllItems(queuer.getAllItems())\n setExecutionCount(queuer.getExecutionCount())\n setIsEmpty(queuer.getIsEmpty())\n setIsFull(queuer.getIsFull())\n setIsIdle(queuer.getIsIdle())\n setPeek(() => queuer.getPeek())\n setSize(queuer.getSize())\n\n const onItemsChange =\n newOptions.onItemsChange ?? initialOptions.onItemsChange\n onItemsChange?.(queuer)\n },\n onIsRunningChange: (queuer) => {\n setIsRunning(queuer.getIsRunning())\n setIsIdle(queuer.getIsIdle())\n\n const onIsRunningChange =\n newOptions.onIsRunningChange ?? initialOptions.onIsRunningChange\n onIsRunningChange?.(queuer)\n },\n onReject: (item, queuer) => {\n setRejectionCount(queuer.getRejectionCount())\n\n const onReject = newOptions.onReject ?? initialOptions.onReject\n onReject?.(item, queuer)\n },\n })\n }\n\n setOptions(initialOptions)\n\n return {\n ...bindInstanceMethods(queuer),\n allItems,\n executionCount,\n isEmpty,\n isFull,\n isIdle,\n isRunning,\n peek,\n rejectionCount,\n size,\n setOptions,\n }\n}\n"],"names":["queuer","Queuer","createSignal","bindInstanceMethods"],"mappings":";;;;;AAiGgB,SAAA,aACd,iBAAwC,IACnB;AACf,QAAAA,WAAS,IAAIC,OAAA,OAAe,cAAc;AAE1C,QAAA,CAAC,UAAU,WAAW,IAAIC,QAAA;AAAA,IAC9BF,SAAO,YAAY;AAAA,EACrB;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,SAAO,kBAAkB;AAAA,EAC3B;AACM,QAAA,CAAC,gBAAgB,iBAAiB,IAAIE,QAAA;AAAA,IAC1CF,SAAO,kBAAkB;AAAA,EAC3B;AACA,QAAM,CAAC,SAAS,UAAU,IAAIE,QAAAA,aAAaF,SAAO,YAAY;AAC9D,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,SAAO,WAAW;AAC3D,QAAM,CAAC,QAAQ,SAAS,IAAIE,QAAAA,aAAaF,SAAO,WAAW;AAC3D,QAAM,CAAC,WAAW,YAAY,IAAIE,QAAAA,aAAaF,SAAO,cAAc;AACpE,QAAM,CAAC,MAAM,OAAO,IAAIE,QAAAA,aAAiCF,SAAO,SAAS;AACzE,QAAM,CAAC,MAAM,OAAO,IAAIE,QAAAA,aAAaF,SAAO,SAAS;AAErD,WAAS,WAAW,YAA4C;AAC9DA,aAAO,WAAW;AAAA,MAChB,GAAG;AAAA,MACH,eAAe,CAACA,YAAW;AACbA,oBAAAA,QAAO,aAAa;AACdA,0BAAAA,QAAO,mBAAmB;AACjCA,mBAAAA,QAAO,YAAY;AACpBA,kBAAAA,QAAO,WAAW;AAClBA,kBAAAA,QAAO,WAAW;AACpB,gBAAA,MAAMA,QAAO,SAAS;AACtBA,gBAAAA,QAAO,SAAS;AAElB,cAAA,gBACJ,WAAW,iBAAiB,eAAe;AAC7C,uDAAgBA;AAAAA,MAClB;AAAA,MACA,mBAAmB,CAACA,YAAW;AAChBA,qBAAAA,QAAO,cAAc;AACxBA,kBAAAA,QAAO,WAAW;AAEtB,cAAA,oBACJ,WAAW,qBAAqB,eAAe;AACjD,+DAAoBA;AAAAA,MACtB;AAAA,MACA,UAAU,CAAC,MAAMA,YAAW;AACRA,0BAAAA,QAAO,mBAAmB;AAEtC,cAAA,WAAW,WAAW,YAAY,eAAe;AACvD,6CAAW,MAAMA;AAAAA,MAAM;AAAA,IACzB,CACD;AAAA,EAAA;AAGH,aAAW,cAAc;AAElB,SAAA;AAAA,IACL,GAAGG,MAAAA,oBAAoBH,QAAM;AAAA,IAC7B;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Queuer, QueuerOptions } from '@tanstack/pacer/queuer';
|
|
2
|
+
import { Accessor } from 'solid-js';
|
|
3
|
+
export interface SolidQueuer<TValue> extends Omit<Queuer<TValue>, 'getAllItems' | 'getExecutionCount' | 'getIsEmpty' | 'getIsFull' | 'getIsIdle' | 'getIsRunning' | 'getPeek' | 'getSize'> {
|
|
4
|
+
/**
|
|
5
|
+
* Signal version of `getAllItems`
|
|
6
|
+
*/
|
|
7
|
+
allItems: Accessor<Array<TValue>>;
|
|
8
|
+
/**
|
|
9
|
+
* Signal version of `getExecutionCount`
|
|
10
|
+
*/
|
|
11
|
+
executionCount: Accessor<number>;
|
|
12
|
+
/**
|
|
13
|
+
* Signal version of `getIsEmpty`
|
|
14
|
+
*/
|
|
15
|
+
isEmpty: Accessor<boolean>;
|
|
16
|
+
/**
|
|
17
|
+
* Signal version of `getIsFull`
|
|
18
|
+
*/
|
|
19
|
+
isFull: Accessor<boolean>;
|
|
20
|
+
/**
|
|
21
|
+
* Signal version of `getIsIdle`
|
|
22
|
+
*/
|
|
23
|
+
isIdle: Accessor<boolean>;
|
|
24
|
+
/**
|
|
25
|
+
* Signal version of `getIsRunning`
|
|
26
|
+
*/
|
|
27
|
+
isRunning: Accessor<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Signal version of `getPeek`
|
|
30
|
+
*/
|
|
31
|
+
peek: Accessor<TValue | undefined>;
|
|
32
|
+
/**
|
|
33
|
+
* Signal version of `getSize`
|
|
34
|
+
*/
|
|
35
|
+
size: Accessor<number>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* A Solid hook that creates and manages a Queuer instance.
|
|
39
|
+
*
|
|
40
|
+
* This is a lower-level hook that provides direct access to the Queuer's functionality without
|
|
41
|
+
* any built-in state management. This allows you to integrate it with any state management solution
|
|
42
|
+
* you prefer (createSignal, Redux, Zustand, etc.) by utilizing the onItemsChange callback.
|
|
43
|
+
*
|
|
44
|
+
* For a hook with built-in state management, see createQueuerSignal.
|
|
45
|
+
*
|
|
46
|
+
* The Queuer extends the base Queue to add processing capabilities. Items are processed
|
|
47
|
+
* synchronously in order, with optional delays between processing each item. The queuer includes
|
|
48
|
+
* an internal tick mechanism that can be started and stopped, making it useful as a scheduler.
|
|
49
|
+
* When started, it will process one item per tick, with an optional wait time between ticks.
|
|
50
|
+
*
|
|
51
|
+
* By default uses FIFO (First In First Out) behavior, but can be configured for LIFO
|
|
52
|
+
* (Last In First Out) by specifying 'front' position when adding items.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```tsx
|
|
56
|
+
* // Example with custom state management and scheduling
|
|
57
|
+
* const [items, setItems] = createSignal([]);
|
|
58
|
+
*
|
|
59
|
+
* const queue = createQueuer({
|
|
60
|
+
* started: true, // Start processing immediately
|
|
61
|
+
* wait: 1000, // Process one item every second
|
|
62
|
+
* onItemsChange: (queue) => setItems(queue.getAllItems()),
|
|
63
|
+
* getPriority: (item) => item.priority // Process higher priority items first
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* // Add items to process - they'll be handled automatically
|
|
67
|
+
* queue.addItem('task1');
|
|
68
|
+
* queue.addItem('task2');
|
|
69
|
+
*
|
|
70
|
+
* // Control the scheduler
|
|
71
|
+
* queue.stop(); // Pause processing
|
|
72
|
+
* queue.start(); // Resume processing
|
|
73
|
+
*
|
|
74
|
+
* // Access queue state via signals
|
|
75
|
+
* console.log('Items:', queue.allItems());
|
|
76
|
+
* console.log('Size:', queue.size());
|
|
77
|
+
* console.log('Is empty:', queue.isEmpty());
|
|
78
|
+
* console.log('Is running:', queue.isRunning());
|
|
79
|
+
* console.log('Next item:', queue.peek());
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
export declare function createQueuer<TValue>(initialOptions?: QueuerOptions<TValue>): SolidQueuer<TValue>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const queuer = require("@tanstack/pacer/queuer");
|
|
4
|
+
const createQueuer = require("./createQueuer.cjs");
|
|
5
|
+
exports.createQueuer = createQueuer.createQueuer;
|
|
6
|
+
Object.keys(queuer).forEach((k) => {
|
|
7
|
+
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: () => queuer[k]
|
|
10
|
+
});
|
|
11
|
+
});
|
|
12
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const solidJs = require("solid-js");
|
|
4
|
+
const createRateLimiter = require("./createRateLimiter.cjs");
|
|
5
|
+
function createRateLimitedSignal(value, initialOptions) {
|
|
6
|
+
const [rateLimitedValue, setRateLimitedValue] = solidJs.createSignal(value);
|
|
7
|
+
const rateLimiter = createRateLimiter.createRateLimiter(setRateLimitedValue, initialOptions);
|
|
8
|
+
return [
|
|
9
|
+
rateLimitedValue,
|
|
10
|
+
rateLimiter.maybeExecute.bind(rateLimiter),
|
|
11
|
+
rateLimiter
|
|
12
|
+
];
|
|
13
|
+
}
|
|
14
|
+
exports.createRateLimitedSignal = createRateLimitedSignal;
|
|
15
|
+
//# sourceMappingURL=createRateLimitedSignal.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedSignal.cjs","sources":["../../../src/rate-limiter/createRateLimitedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createRateLimiter } from './createRateLimiter'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.\n * This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns a tuple containing:\n * - The rate-limited state value accessor\n * - A rate-limited setter function that respects the configured limits\n * - The rateLimiter instance for additional control\n *\n * For more direct control over rate limiting without state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update state at most 5 times per minute\n * const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [value, setValue] = createRateLimitedSignal(0, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * setValue(newValue);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n * ```\n */\nexport function createRateLimitedSignal<TValue>(\n value: TValue,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>,\n] {\n const [rateLimitedValue, setRateLimitedValue] = createSignal<TValue>(value)\n\n const rateLimiter = createRateLimiter(setRateLimitedValue, initialOptions)\n\n return [\n rateLimitedValue,\n rateLimiter.maybeExecute.bind(rateLimiter) as Setter<TValue>,\n rateLimiter,\n ]\n}\n"],"names":["createSignal","createRateLimiter"],"mappings":";;;;AAwDgB,SAAA,wBACd,OACA,gBAKA;AACA,QAAM,CAAC,kBAAkB,mBAAmB,IAAIA,QAAAA,aAAqB,KAAK;AAEpE,QAAA,cAAcC,kBAAAA,kBAAkB,qBAAqB,cAAc;AAElE,SAAA;AAAA,IACL;AAAA,IACA,YAAY,aAAa,KAAK,WAAW;AAAA,IACzC;AAAA,EACF;AACF;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { SolidRateLimiter } from './createRateLimiter.cjs';
|
|
2
|
+
import { Accessor, Setter } from 'solid-js';
|
|
3
|
+
import { RateLimiterOptions } from '@tanstack/pacer/rate-limiter';
|
|
4
|
+
/**
|
|
5
|
+
* A Solid hook that creates a rate-limited state value that enforces a hard limit on state updates within a time window.
|
|
6
|
+
* This hook combines Solid's createSignal with rate limiting functionality to provide controlled state updates.
|
|
7
|
+
*
|
|
8
|
+
* Rate limiting is a simple "hard limit" approach - it allows all updates until the limit is reached, then blocks
|
|
9
|
+
* subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out
|
|
10
|
+
* or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.
|
|
11
|
+
*
|
|
12
|
+
* For smoother update patterns, consider:
|
|
13
|
+
* - createThrottledSignal: When you want consistent spacing between updates (e.g. UI changes)
|
|
14
|
+
* - createDebouncedSignal: When you want to collapse rapid updates into a single update (e.g. search input)
|
|
15
|
+
*
|
|
16
|
+
* Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.
|
|
17
|
+
*
|
|
18
|
+
* The hook returns a tuple containing:
|
|
19
|
+
* - The rate-limited state value accessor
|
|
20
|
+
* - A rate-limited setter function that respects the configured limits
|
|
21
|
+
* - The rateLimiter instance for additional control
|
|
22
|
+
*
|
|
23
|
+
* For more direct control over rate limiting without state management,
|
|
24
|
+
* consider using the lower-level createRateLimiter hook instead.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* // Basic rate limiting - update state at most 5 times per minute
|
|
29
|
+
* const [value, setValue, rateLimiter] = createRateLimitedSignal(0, {
|
|
30
|
+
* limit: 5,
|
|
31
|
+
* window: 60000
|
|
32
|
+
* });
|
|
33
|
+
*
|
|
34
|
+
* // With rejection callback
|
|
35
|
+
* const [value, setValue] = createRateLimitedSignal(0, {
|
|
36
|
+
* limit: 3,
|
|
37
|
+
* window: 5000,
|
|
38
|
+
* onReject: (rateLimiter) => {
|
|
39
|
+
* alert(`Rate limit reached. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
|
|
40
|
+
* }
|
|
41
|
+
* });
|
|
42
|
+
*
|
|
43
|
+
* // Access rateLimiter state via signals
|
|
44
|
+
* const handleSubmit = () => {
|
|
45
|
+
* const remaining = rateLimiter.remainingInWindow();
|
|
46
|
+
* if (remaining > 0) {
|
|
47
|
+
* setValue(newValue);
|
|
48
|
+
* } else {
|
|
49
|
+
* showRateLimitWarning();
|
|
50
|
+
* }
|
|
51
|
+
* };
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
export declare function createRateLimitedSignal<TValue>(value: TValue, initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>): [
|
|
55
|
+
Accessor<TValue>,
|
|
56
|
+
Setter<TValue>,
|
|
57
|
+
SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>
|
|
58
|
+
];
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const solidJs = require("solid-js");
|
|
4
|
+
const createRateLimitedSignal = require("./createRateLimitedSignal.cjs");
|
|
5
|
+
function createRateLimitedValue(value, initialOptions) {
|
|
6
|
+
const [rateLimitedValue, setRateLimitedValue, rateLimiter] = createRateLimitedSignal.createRateLimitedSignal(value(), initialOptions);
|
|
7
|
+
solidJs.createEffect(() => {
|
|
8
|
+
setRateLimitedValue(value());
|
|
9
|
+
});
|
|
10
|
+
return [rateLimitedValue, rateLimiter];
|
|
11
|
+
}
|
|
12
|
+
exports.createRateLimitedValue = createRateLimitedValue;
|
|
13
|
+
//# sourceMappingURL=createRateLimitedValue.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createRateLimitedValue.cjs","sources":["../../../src/rate-limiter/createRateLimitedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createRateLimitedSignal } from './createRateLimitedSignal'\nimport type { SolidRateLimiter } from './createRateLimiter'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { RateLimiterOptions } from '@tanstack/pacer/rate-limiter'\n\n/**\n * A high-level Solid hook that creates a rate-limited version of a value that updates at most a certain number of times within a time window.\n * This hook uses Solid's createSignal internally to manage the rate-limited state.\n *\n * Rate limiting is a simple \"hard limit\" approach - it allows all updates until the limit is reached, then blocks\n * subsequent updates until the window resets. Unlike throttling or debouncing, it does not attempt to space out\n * or intelligently collapse updates. This can lead to bursts of rapid updates followed by periods of no updates.\n *\n * For smoother update patterns, consider:\n * - createThrottledValue: When you want consistent spacing between updates (e.g. UI changes)\n * - createDebouncedValue: When you want to collapse rapid updates into a single update (e.g. search input)\n *\n * Rate limiting should primarily be used when you need to enforce strict limits, like API rate limits.\n *\n * The hook returns both the rate-limited value and the underlying rateLimiter instance for additional control.\n *\n * For more direct control over rate limiting behavior without Solid state management,\n * consider using the lower-level createRateLimiter hook instead.\n *\n * @example\n * ```tsx\n * // Basic rate limiting - update at most 5 times per minute\n * const [rateLimitedValue] = createRateLimitedValue(rawValue, {\n * limit: 5,\n * window: 60000\n * });\n *\n * // With rejection callback\n * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {\n * limit: 3,\n * window: 5000,\n * onReject: (rateLimiter) => {\n * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Optionally access rateLimiter state via signals\n * const handleSubmit = () => {\n * const remaining = rateLimiter.remainingInWindow();\n * if (remaining > 0) {\n * console.log(`${remaining} updates remaining in this window`);\n * } else {\n * console.log('Rate limit reached for this window');\n * }\n * };\n * ```\n */\nexport function createRateLimitedValue<TValue>(\n value: Accessor<TValue>,\n initialOptions: RateLimiterOptions<Setter<TValue>, [Accessor<TValue>]>,\n): [Accessor<TValue>, SolidRateLimiter<Setter<TValue>, [Accessor<TValue>]>] {\n const [rateLimitedValue, setRateLimitedValue, rateLimiter] =\n createRateLimitedSignal(value(), initialOptions)\n\n createEffect(() => {\n setRateLimitedValue(value() as any)\n })\n\n return [rateLimitedValue, rateLimiter]\n}\n"],"names":["createRateLimitedSignal","createEffect"],"mappings":";;;;AAqDgB,SAAA,uBACd,OACA,gBAC0E;AACpE,QAAA,CAAC,kBAAkB,qBAAqB,WAAW,IACvDA,gDAAwB,SAAS,cAAc;AAEjDC,UAAAA,aAAa,MAAM;AACjB,wBAAoB,OAAc;AAAA,EAAA,CACnC;AAEM,SAAA,CAAC,kBAAkB,WAAW;AACvC;;"}
|