@tanstack/solid-pacer 0.18.4 → 0.19.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/README.md +1 -1
- package/dist/async-batcher/createAsyncBatcher.cjs +32 -2
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +28 -2
- package/dist/async-batcher/createAsyncBatcher.d.ts +28 -2
- package/dist/async-batcher/createAsyncBatcher.js +32 -2
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
- package/dist/async-batcher/index.cjs +1 -0
- package/dist/async-batcher/index.d.cts +2 -2
- package/dist/async-batcher/index.d.ts +2 -2
- package/dist/async-debouncer/createAsyncDebouncer.cjs +26 -3
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +27 -2
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +27 -2
- package/dist/async-debouncer/createAsyncDebouncer.js +26 -3
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/async-debouncer/index.cjs +1 -0
- package/dist/async-debouncer/index.d.cts +2 -2
- package/dist/async-debouncer/index.d.ts +2 -2
- package/dist/async-queuer/createAsyncQueuer.cjs +32 -2
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +28 -2
- package/dist/async-queuer/createAsyncQueuer.d.ts +28 -2
- package/dist/async-queuer/createAsyncQueuer.js +32 -2
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/async-queuer/index.cjs +1 -0
- package/dist/async-queuer/index.d.cts +2 -2
- package/dist/async-queuer/index.d.ts +2 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +16 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +15 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +15 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +16 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/async-rate-limiter/index.cjs +1 -0
- package/dist/async-rate-limiter/index.d.cts +2 -2
- package/dist/async-rate-limiter/index.d.ts +2 -2
- package/dist/async-throttler/createAsyncThrottler.cjs +31 -2
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +27 -2
- package/dist/async-throttler/createAsyncThrottler.d.ts +27 -2
- package/dist/async-throttler/createAsyncThrottler.js +31 -2
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
- package/dist/async-throttler/index.cjs +1 -0
- package/dist/async-throttler/index.d.cts +2 -2
- package/dist/async-throttler/index.d.ts +2 -2
- package/dist/batcher/createBatcher.cjs +23 -2
- package/dist/batcher/createBatcher.cjs.map +1 -1
- package/dist/batcher/createBatcher.d.cts +22 -2
- package/dist/batcher/createBatcher.d.ts +22 -2
- package/dist/batcher/createBatcher.js +23 -2
- package/dist/batcher/createBatcher.js.map +1 -1
- package/dist/batcher/index.cjs +1 -0
- package/dist/batcher/index.d.cts +2 -2
- package/dist/batcher/index.d.ts +2 -2
- package/dist/debouncer/createDebouncedSignal.cjs.map +1 -1
- package/dist/debouncer/createDebouncedSignal.d.cts +3 -3
- package/dist/debouncer/createDebouncedSignal.d.ts +3 -3
- package/dist/debouncer/createDebouncedSignal.js.map +1 -1
- package/dist/debouncer/createDebouncedValue.cjs.map +1 -1
- package/dist/debouncer/createDebouncedValue.d.cts +3 -3
- package/dist/debouncer/createDebouncedValue.d.ts +3 -3
- package/dist/debouncer/createDebouncedValue.js.map +1 -1
- package/dist/debouncer/createDebouncer.cjs +17 -3
- package/dist/debouncer/createDebouncer.cjs.map +1 -1
- package/dist/debouncer/createDebouncer.d.cts +21 -2
- package/dist/debouncer/createDebouncer.d.ts +21 -2
- package/dist/debouncer/createDebouncer.js +17 -3
- package/dist/debouncer/createDebouncer.js.map +1 -1
- package/dist/debouncer/index.cjs +1 -0
- package/dist/debouncer/index.d.cts +2 -2
- package/dist/debouncer/index.d.ts +2 -2
- package/dist/index.cjs +1 -0
- package/dist/index.d.cts +11 -11
- package/dist/index.d.ts +11 -11
- package/dist/provider/index.cjs +1 -0
- package/dist/queuer/createQueuedSignal.cjs.map +1 -1
- package/dist/queuer/createQueuedSignal.d.cts +3 -3
- package/dist/queuer/createQueuedSignal.d.ts +3 -3
- package/dist/queuer/createQueuedSignal.js.map +1 -1
- package/dist/queuer/createQueuer.cjs +23 -2
- package/dist/queuer/createQueuer.cjs.map +1 -1
- package/dist/queuer/createQueuer.d.cts +22 -2
- package/dist/queuer/createQueuer.d.ts +22 -2
- package/dist/queuer/createQueuer.js +23 -2
- package/dist/queuer/createQueuer.js.map +1 -1
- package/dist/queuer/index.cjs +1 -0
- package/dist/queuer/index.d.cts +2 -2
- package/dist/queuer/index.d.ts +2 -2
- package/dist/rate-limiter/createRateLimitedSignal.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimitedSignal.d.cts +3 -3
- package/dist/rate-limiter/createRateLimitedSignal.d.ts +3 -3
- package/dist/rate-limiter/createRateLimitedSignal.js.map +1 -1
- package/dist/rate-limiter/createRateLimitedValue.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimitedValue.d.cts +3 -3
- package/dist/rate-limiter/createRateLimitedValue.d.ts +3 -3
- package/dist/rate-limiter/createRateLimitedValue.js.map +1 -1
- package/dist/rate-limiter/createRateLimiter.cjs +9 -2
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +9 -2
- package/dist/rate-limiter/createRateLimiter.d.ts +9 -2
- package/dist/rate-limiter/createRateLimiter.js +9 -2
- package/dist/rate-limiter/createRateLimiter.js.map +1 -1
- package/dist/rate-limiter/index.cjs +1 -0
- package/dist/rate-limiter/index.d.cts +2 -2
- package/dist/rate-limiter/index.d.ts +2 -2
- package/dist/throttler/createThrottledSignal.cjs.map +1 -1
- package/dist/throttler/createThrottledSignal.d.cts +3 -3
- package/dist/throttler/createThrottledSignal.d.ts +3 -3
- package/dist/throttler/createThrottledSignal.js.map +1 -1
- package/dist/throttler/createThrottledValue.cjs.map +1 -1
- package/dist/throttler/createThrottledValue.d.cts +3 -3
- package/dist/throttler/createThrottledValue.d.ts +3 -3
- package/dist/throttler/createThrottledValue.js.map +1 -1
- package/dist/throttler/createThrottler.cjs +17 -3
- package/dist/throttler/createThrottler.cjs.map +1 -1
- package/dist/throttler/createThrottler.d.cts +21 -2
- package/dist/throttler/createThrottler.d.ts +21 -2
- package/dist/throttler/createThrottler.js +17 -3
- package/dist/throttler/createThrottler.js.map +1 -1
- package/dist/throttler/index.cjs +1 -0
- package/dist/throttler/index.d.cts +2 -2
- package/dist/throttler/index.d.ts +2 -2
- package/package.json +32 -31
- package/src/async-batcher/createAsyncBatcher.ts +44 -3
- package/src/async-debouncer/createAsyncDebouncer.ts +37 -4
- package/src/async-queuer/createAsyncQueuer.ts +44 -3
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +30 -3
- package/src/async-throttler/createAsyncThrottler.ts +43 -3
- package/src/batcher/createBatcher.ts +38 -3
- package/src/debouncer/createDebouncedSignal.ts +3 -6
- package/src/debouncer/createDebouncedValue.ts +3 -6
- package/src/debouncer/createDebouncer.ts +30 -4
- package/src/queuer/createQueuedSignal.ts +3 -3
- package/src/queuer/createQueuer.ts +37 -3
- package/src/rate-limiter/createRateLimitedSignal.ts +6 -6
- package/src/rate-limiter/createRateLimitedValue.ts +6 -6
- package/src/rate-limiter/createRateLimiter.ts +22 -3
- package/src/throttler/createThrottledSignal.ts +3 -6
- package/src/throttler/createThrottledValue.ts +3 -6
- package/src/throttler/createThrottler.ts +30 -4
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
|
+
import { createEffect, onCleanup } from "solid-js";
|
|
2
3
|
import { useStore } from "@tanstack/solid-store";
|
|
3
4
|
import { Batcher } from "@tanstack/pacer/batcher";
|
|
4
5
|
|
|
@@ -45,6 +46,19 @@ import { Batcher } from "@tanstack/pacer/batcher";
|
|
|
45
46
|
* - `items`: Array of items currently queued for batching
|
|
46
47
|
* - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
|
|
47
48
|
*
|
|
49
|
+
* ## Unmount behavior
|
|
50
|
+
*
|
|
51
|
+
* By default, the primitive cancels any pending batch when the owning component unmounts.
|
|
52
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
53
|
+
*
|
|
54
|
+
* ```tsx
|
|
55
|
+
* const batcher = createBatcher(fn, {
|
|
56
|
+
* maxSize: 10,
|
|
57
|
+
* wait: 2000,
|
|
58
|
+
* onUnmount: (b) => b.flush()
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
48
62
|
* Example usage:
|
|
49
63
|
* ```tsx
|
|
50
64
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -91,15 +105,22 @@ import { Batcher } from "@tanstack/pacer/batcher";
|
|
|
91
105
|
* ```
|
|
92
106
|
*/
|
|
93
107
|
function createBatcher(fn, options = {}, selector = () => ({})) {
|
|
94
|
-
const
|
|
108
|
+
const mergedOptions = {
|
|
95
109
|
...useDefaultPacerOptions().batcher,
|
|
96
110
|
...options
|
|
97
|
-
}
|
|
111
|
+
};
|
|
112
|
+
const batcher = new Batcher(fn, mergedOptions);
|
|
98
113
|
batcher.Subscribe = function Subscribe(props) {
|
|
99
114
|
const selected = useStore(batcher.store, props.selector);
|
|
100
115
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
101
116
|
};
|
|
102
117
|
const state = useStore(batcher.store, selector);
|
|
118
|
+
createEffect(() => {
|
|
119
|
+
onCleanup(() => {
|
|
120
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(batcher);
|
|
121
|
+
else batcher.cancel();
|
|
122
|
+
});
|
|
123
|
+
});
|
|
103
124
|
return {
|
|
104
125
|
...batcher,
|
|
105
126
|
state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBatcher.js","names":[],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options:
|
|
1
|
+
{"version":3,"file":"createBatcher.js","names":[],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\nimport { useStore } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const batcher = createBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: SolidBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as SolidBatcherOptions<TValue, TSelected>\n const batcher = new Batcher(fn, mergedOptions) as unknown as SolidBatcher<\n TValue,\n TSelected\n >\n\n batcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(batcher.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(batcher.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(batcher)\n } else {\n batcher.cancel()\n }\n })\n })\n\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,cACd,IACA,UAAkD,EAAE,EACpD,kBACG,EAAE,GAC4B;CACjC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,UAAU,IAAI,QAAQ,IAAI,cAAc;AAK9C,SAAQ,YAAY,SAAS,UAAqB,OAG/C;EACD,MAAM,WAAW,SAAS,QAAQ,OAAO,MAAM,SAAS;AAExD,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,QAAQ,OAAO,SAAS;AAE/C,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,QAAQ;OAEhC,SAAQ,QAAQ;IAElB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
package/dist/batcher/index.cjs
CHANGED
package/dist/batcher/index.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SolidBatcher, createBatcher } from "./createBatcher.cjs";
|
|
1
|
+
import { SolidBatcher, SolidBatcherOptions, createBatcher } from "./createBatcher.cjs";
|
|
2
2
|
export * from "@tanstack/pacer/batcher";
|
|
3
|
-
export { SolidBatcher, createBatcher };
|
|
3
|
+
export { SolidBatcher, SolidBatcherOptions, createBatcher };
|
package/dist/batcher/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { SolidBatcher, createBatcher } from "./createBatcher.js";
|
|
1
|
+
import { SolidBatcher, SolidBatcherOptions, createBatcher } from "./createBatcher.js";
|
|
2
2
|
export * from "@tanstack/pacer/batcher";
|
|
3
|
-
export { SolidBatcher, createBatcher };
|
|
3
|
+
export { SolidBatcher, SolidBatcherOptions, createBatcher };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncedSignal.cjs","names":["createDebouncer"],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createDebouncedSignal.cjs","names":["createDebouncer"],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.state().executionCount);\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions, selector)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,gDAA0C,MAAM;CAEvE,MAAM,YAAYA,wCAAgB,mBAAmB,gBAAgB,SAAS;AAE9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SolidDebouncer } from "./createDebouncer.cjs";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.cjs";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
4
|
|
|
5
5
|
//#region src/debouncer/createDebouncedSignal.d.ts
|
|
6
6
|
/**
|
|
@@ -74,7 +74,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
|
74
74
|
* });
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
declare function createDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions:
|
|
77
|
+
declare function createDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
|
|
78
78
|
//#endregion
|
|
79
79
|
export { createDebouncedSignal };
|
|
80
80
|
//# sourceMappingURL=createDebouncedSignal.d.cts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SolidDebouncer } from "./createDebouncer.js";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.js";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
4
|
|
|
5
5
|
//#region src/debouncer/createDebouncedSignal.d.ts
|
|
6
6
|
/**
|
|
@@ -74,7 +74,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
|
74
74
|
* });
|
|
75
75
|
* ```
|
|
76
76
|
*/
|
|
77
|
-
declare function createDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions:
|
|
77
|
+
declare function createDebouncedSignal<TValue, TSelected = {}>(value: TValue, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, Setter<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
|
|
78
78
|
//#endregion
|
|
79
79
|
export { createDebouncedSignal };
|
|
80
80
|
//# sourceMappingURL=createDebouncedSignal.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncedSignal.js","names":[],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createDebouncedSignal.js","names":[],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.state().executionCount);\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions, selector)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,MAAM;CAEvE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,SAAS;AAE9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncedValue.cjs","names":["createDebouncedSignal"],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createDebouncedValue.cjs","names":["createDebouncedSignal"],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } 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 * - An Accessor that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = createDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\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('Is pending:', debouncer.state().isPending);\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,OAAO,EACP,gBACA,SACD;AAED,kCAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SolidDebouncer } from "./createDebouncer.cjs";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.cjs";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
4
|
|
|
5
5
|
//#region src/debouncer/createDebouncedValue.d.ts
|
|
6
6
|
/**
|
|
@@ -65,7 +65,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
|
65
65
|
* debouncer.cancel(); // Cancel any pending updates
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
|
-
declare function createDebouncedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
68
|
+
declare function createDebouncedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
|
|
69
69
|
//#endregion
|
|
70
70
|
export { createDebouncedValue };
|
|
71
71
|
//# sourceMappingURL=createDebouncedValue.d.cts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { SolidDebouncer } from "./createDebouncer.js";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions } from "./createDebouncer.js";
|
|
2
2
|
import { Accessor, Setter } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { DebouncerState } from "@tanstack/pacer/debouncer";
|
|
4
4
|
|
|
5
5
|
//#region src/debouncer/createDebouncedValue.d.ts
|
|
6
6
|
/**
|
|
@@ -65,7 +65,7 @@ import { DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
|
65
65
|
* debouncer.cancel(); // Cancel any pending updates
|
|
66
66
|
* ```
|
|
67
67
|
*/
|
|
68
|
-
declare function createDebouncedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions:
|
|
68
|
+
declare function createDebouncedValue<TValue, TSelected = {}>(value: Accessor<TValue>, initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>, selector?: (state: DebouncerState<Setter<TValue>>) => TSelected): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>];
|
|
69
69
|
//#endregion
|
|
70
70
|
export { createDebouncedValue };
|
|
71
71
|
//# sourceMappingURL=createDebouncedValue.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncedValue.js","names":[],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {
|
|
1
|
+
{"version":3,"file":"createDebouncedValue.js","names":[],"sources":["../../src/debouncer/createDebouncedValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createDebouncedSignal } from './createDebouncedSignal'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } 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 * - An Accessor that provides the current debounced value\n * - The debouncer instance with control methods\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchQuery, setSearchQuery] = createSignal('');\n * const [debouncedQuery, debouncer] = createDebouncedValue(searchQuery, {\n * wait: 500 // Wait 500ms after last change\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [debouncedQuery, debouncer] = createDebouncedValue(\n * searchQuery,\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\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('Is pending:', debouncer.state().isPending);\n *\n * // Control the debouncer\n * debouncer.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createDebouncedValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidDebouncer<Setter<TValue>, TSelected>] {\n const [debouncedValue, setDebouncedValue, debouncer] = createDebouncedSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setDebouncedValue(value() as any)\n })\n\n return [debouncedValue, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,OAAO,EACP,gBACA,SACD;AAED,oBAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
|
|
@@ -47,6 +47,18 @@ let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
|
|
|
47
47
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
48
48
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
49
49
|
*
|
|
50
|
+
* ## Unmount behavior
|
|
51
|
+
*
|
|
52
|
+
* By default, the primitive cancels any pending execution when the owning component unmounts.
|
|
53
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
54
|
+
*
|
|
55
|
+
* ```tsx
|
|
56
|
+
* const debouncer = createDebouncer(fn, {
|
|
57
|
+
* wait: 500,
|
|
58
|
+
* onUnmount: (d) => d.flush()
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
50
62
|
* @example
|
|
51
63
|
* ```tsx
|
|
52
64
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -90,10 +102,11 @@ let _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
|
|
|
90
102
|
* ```
|
|
91
103
|
*/
|
|
92
104
|
function createDebouncer(fn, options, selector = () => ({})) {
|
|
93
|
-
const
|
|
105
|
+
const mergedOptions = {
|
|
94
106
|
...require_PacerProvider.useDefaultPacerOptions().debouncer,
|
|
95
107
|
...options
|
|
96
|
-
}
|
|
108
|
+
};
|
|
109
|
+
const asyncDebouncer = new _tanstack_pacer_debouncer.Debouncer(fn, mergedOptions);
|
|
97
110
|
asyncDebouncer.Subscribe = function Subscribe(props) {
|
|
98
111
|
const selected = (0, _tanstack_solid_store.useStore)(asyncDebouncer.store, props.selector);
|
|
99
112
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
@@ -101,7 +114,8 @@ function createDebouncer(fn, options, selector = () => ({})) {
|
|
|
101
114
|
const state = (0, _tanstack_solid_store.useStore)(asyncDebouncer.store, selector);
|
|
102
115
|
(0, solid_js.createEffect)(() => {
|
|
103
116
|
(0, solid_js.onCleanup)(() => {
|
|
104
|
-
|
|
117
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncDebouncer);
|
|
118
|
+
else asyncDebouncer.cancel();
|
|
105
119
|
});
|
|
106
120
|
});
|
|
107
121
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncer.cjs","names":["
|
|
1
|
+
{"version":3,"file":"createDebouncer.cjs","names":["useDefaultPacerOptions","Debouncer"],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncDebouncer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncDebouncer.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAIC,oCACzB,IACA,cACD;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,+CAAoB,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,eAAe,OAAO,SAAS;AAEtD,kCAAmB;AACjB,gCAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,eAAe;OAEvC,gBAAe,QAAQ;IAEzB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -4,6 +4,13 @@ import { AnyFunction } from "@tanstack/pacer/types";
|
|
|
4
4
|
import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
|
|
5
5
|
|
|
6
6
|
//#region src/debouncer/createDebouncer.d.ts
|
|
7
|
+
interface SolidDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the owning component unmounts. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* A Solid component that allows you to subscribe to the debouncer state.
|
|
@@ -78,6 +85,18 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
|
|
|
78
85
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
79
86
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
80
87
|
*
|
|
88
|
+
* ## Unmount behavior
|
|
89
|
+
*
|
|
90
|
+
* By default, the primitive cancels any pending execution when the owning component unmounts.
|
|
91
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
92
|
+
*
|
|
93
|
+
* ```tsx
|
|
94
|
+
* const debouncer = createDebouncer(fn, {
|
|
95
|
+
* wait: 500,
|
|
96
|
+
* onUnmount: (d) => d.flush()
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
81
100
|
* @example
|
|
82
101
|
* ```tsx
|
|
83
102
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -120,7 +139,7 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
|
|
|
120
139
|
* const { isPending } = debouncer.state();
|
|
121
140
|
* ```
|
|
122
141
|
*/
|
|
123
|
-
declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
142
|
+
declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): SolidDebouncer<TFn, TSelected>;
|
|
124
143
|
//#endregion
|
|
125
|
-
export { SolidDebouncer, createDebouncer };
|
|
144
|
+
export { SolidDebouncer, SolidDebouncerOptions, createDebouncer };
|
|
126
145
|
//# sourceMappingURL=createDebouncer.d.cts.map
|
|
@@ -4,6 +4,13 @@ import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/deb
|
|
|
4
4
|
import { AnyFunction } from "@tanstack/pacer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/debouncer/createDebouncer.d.ts
|
|
7
|
+
interface SolidDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
|
|
8
|
+
/**
|
|
9
|
+
* Optional callback invoked when the owning component unmounts. Receives the debouncer instance.
|
|
10
|
+
* When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
|
|
11
|
+
*/
|
|
12
|
+
onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void;
|
|
13
|
+
}
|
|
7
14
|
interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
|
|
8
15
|
/**
|
|
9
16
|
* A Solid component that allows you to subscribe to the debouncer state.
|
|
@@ -78,6 +85,18 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
|
|
|
78
85
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
79
86
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
80
87
|
*
|
|
88
|
+
* ## Unmount behavior
|
|
89
|
+
*
|
|
90
|
+
* By default, the primitive cancels any pending execution when the owning component unmounts.
|
|
91
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
92
|
+
*
|
|
93
|
+
* ```tsx
|
|
94
|
+
* const debouncer = createDebouncer(fn, {
|
|
95
|
+
* wait: 500,
|
|
96
|
+
* onUnmount: (d) => d.flush()
|
|
97
|
+
* });
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
81
100
|
* @example
|
|
82
101
|
* ```tsx
|
|
83
102
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -120,7 +139,7 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
|
|
|
120
139
|
* const { isPending } = debouncer.state();
|
|
121
140
|
* ```
|
|
122
141
|
*/
|
|
123
|
-
declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options:
|
|
142
|
+
declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): SolidDebouncer<TFn, TSelected>;
|
|
124
143
|
//#endregion
|
|
125
|
-
export { SolidDebouncer, createDebouncer };
|
|
144
|
+
export { SolidDebouncer, SolidDebouncerOptions, createDebouncer };
|
|
126
145
|
//# sourceMappingURL=createDebouncer.d.ts.map
|
|
@@ -47,6 +47,18 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
|
|
|
47
47
|
* - `lastArgs`: The arguments from the most recent call to maybeExecute
|
|
48
48
|
* - `status`: Current execution status ('disabled' | 'idle' | 'pending')
|
|
49
49
|
*
|
|
50
|
+
* ## Unmount behavior
|
|
51
|
+
*
|
|
52
|
+
* By default, the primitive cancels any pending execution when the owning component unmounts.
|
|
53
|
+
* Use the `onUnmount` option to customize this. For example, to flush pending work instead:
|
|
54
|
+
*
|
|
55
|
+
* ```tsx
|
|
56
|
+
* const debouncer = createDebouncer(fn, {
|
|
57
|
+
* wait: 500,
|
|
58
|
+
* onUnmount: (d) => d.flush()
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
50
62
|
* @example
|
|
51
63
|
* ```tsx
|
|
52
64
|
* // Default behavior - no reactive state subscriptions
|
|
@@ -90,10 +102,11 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
|
|
|
90
102
|
* ```
|
|
91
103
|
*/
|
|
92
104
|
function createDebouncer(fn, options, selector = () => ({})) {
|
|
93
|
-
const
|
|
105
|
+
const mergedOptions = {
|
|
94
106
|
...useDefaultPacerOptions().debouncer,
|
|
95
107
|
...options
|
|
96
|
-
}
|
|
108
|
+
};
|
|
109
|
+
const asyncDebouncer = new Debouncer(fn, mergedOptions);
|
|
97
110
|
asyncDebouncer.Subscribe = function Subscribe(props) {
|
|
98
111
|
const selected = useStore(asyncDebouncer.store, props.selector);
|
|
99
112
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
@@ -101,7 +114,8 @@ function createDebouncer(fn, options, selector = () => ({})) {
|
|
|
101
114
|
const state = useStore(asyncDebouncer.store, selector);
|
|
102
115
|
createEffect(() => {
|
|
103
116
|
onCleanup(() => {
|
|
104
|
-
|
|
117
|
+
if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncDebouncer);
|
|
118
|
+
else asyncDebouncer.cancel();
|
|
105
119
|
});
|
|
106
120
|
});
|
|
107
121
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options:
|
|
1
|
+
{"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<DebouncerState<TFn>>>\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 * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncDebouncer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncDebouncer.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAI,UACzB,IACA,cACD;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,SAAS,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,eAAe,OAAO,SAAS;AAEtD,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,eAAe;OAEvC,gBAAe,QAAQ;IAEzB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
package/dist/debouncer/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
const require_createDebouncer = require('./createDebouncer.cjs');
|
|
2
3
|
const require_createDebouncedSignal = require('./createDebouncedSignal.cjs');
|
|
3
4
|
const require_createDebouncedValue = require('./createDebouncedValue.cjs');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SolidDebouncer, createDebouncer } from "./createDebouncer.cjs";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions, createDebouncer } from "./createDebouncer.cjs";
|
|
2
2
|
import { createDebouncedSignal } from "./createDebouncedSignal.cjs";
|
|
3
3
|
import { createDebouncedValue } from "./createDebouncedValue.cjs";
|
|
4
4
|
export * from "@tanstack/pacer/debouncer";
|
|
5
|
-
export { SolidDebouncer, createDebouncedSignal, createDebouncedValue, createDebouncer };
|
|
5
|
+
export { SolidDebouncer, SolidDebouncerOptions, createDebouncedSignal, createDebouncedValue, createDebouncer };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { SolidDebouncer, createDebouncer } from "./createDebouncer.js";
|
|
1
|
+
import { SolidDebouncer, SolidDebouncerOptions, createDebouncer } from "./createDebouncer.js";
|
|
2
2
|
import { createDebouncedSignal } from "./createDebouncedSignal.js";
|
|
3
3
|
import { createDebouncedValue } from "./createDebouncedValue.js";
|
|
4
4
|
export * from "@tanstack/pacer/debouncer";
|
|
5
|
-
export { SolidDebouncer, createDebouncedSignal, createDebouncedValue, createDebouncer };
|
|
5
|
+
export { SolidDebouncer, SolidDebouncerOptions, createDebouncedSignal, createDebouncedValue, createDebouncer };
|
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
const require_PacerProvider = require('./provider/PacerProvider.cjs');
|
|
2
3
|
const require_createAsyncBatcher = require('./async-batcher/createAsyncBatcher.cjs');
|
|
3
4
|
const require_createAsyncDebouncer = require('./async-debouncer/createAsyncDebouncer.cjs');
|