@tanstack/solid-pacer 0.20.0 → 0.21.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/dist/async-batcher/createAsyncBatcher.cjs +2 -2
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +2 -2
- package/dist/async-batcher/createAsyncBatcher.d.ts +2 -2
- package/dist/async-batcher/createAsyncBatcher.js +3 -3
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.cjs +2 -2
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +2 -2
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +2 -2
- package/dist/async-debouncer/createAsyncDebouncer.js +3 -3
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.cjs +2 -2
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +2 -2
- package/dist/async-queuer/createAsyncQueuer.d.ts +2 -2
- package/dist/async-queuer/createAsyncQueuer.js +3 -3
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +2 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +2 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +2 -2
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +3 -3
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.cjs +2 -2
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +2 -2
- package/dist/async-throttler/createAsyncThrottler.d.ts +2 -2
- package/dist/async-throttler/createAsyncThrottler.js +3 -3
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
- package/dist/batcher/createBatcher.cjs +2 -2
- package/dist/batcher/createBatcher.cjs.map +1 -1
- package/dist/batcher/createBatcher.d.cts +2 -2
- package/dist/batcher/createBatcher.d.ts +2 -2
- package/dist/batcher/createBatcher.js +3 -3
- package/dist/batcher/createBatcher.js.map +1 -1
- package/dist/debouncer/createDebouncer.cjs +2 -2
- package/dist/debouncer/createDebouncer.cjs.map +1 -1
- package/dist/debouncer/createDebouncer.d.cts +2 -2
- package/dist/debouncer/createDebouncer.d.ts +2 -2
- package/dist/debouncer/createDebouncer.js +3 -3
- package/dist/debouncer/createDebouncer.js.map +1 -1
- package/dist/queuer/createQueuer.cjs +2 -2
- package/dist/queuer/createQueuer.cjs.map +1 -1
- package/dist/queuer/createQueuer.d.cts +2 -2
- package/dist/queuer/createQueuer.d.ts +2 -2
- package/dist/queuer/createQueuer.js +3 -3
- package/dist/queuer/createQueuer.js.map +1 -1
- package/dist/rate-limiter/createRateLimiter.cjs +2 -2
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +2 -2
- package/dist/rate-limiter/createRateLimiter.d.ts +2 -2
- package/dist/rate-limiter/createRateLimiter.js +3 -3
- package/dist/rate-limiter/createRateLimiter.js.map +1 -1
- package/dist/throttler/createThrottler.cjs +2 -2
- package/dist/throttler/createThrottler.cjs.map +1 -1
- package/dist/throttler/createThrottler.d.cts +2 -2
- package/dist/throttler/createThrottler.d.ts +2 -2
- package/dist/throttler/createThrottler.js +3 -3
- package/dist/throttler/createThrottler.js.map +1 -1
- package/package.json +5 -5
- package/src/async-batcher/createAsyncBatcher.ts +7 -5
- package/src/async-debouncer/createAsyncDebouncer.ts +9 -5
- package/src/async-queuer/createAsyncQueuer.ts +7 -5
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +9 -5
- package/src/async-throttler/createAsyncThrottler.ts +9 -5
- package/src/batcher/createBatcher.ts +7 -5
- package/src/debouncer/createDebouncer.ts +9 -5
- package/src/queuer/createQueuer.ts +7 -5
- package/src/rate-limiter/createRateLimiter.ts +7 -5
- package/src/throttler/createThrottler.ts +9 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueuer.cjs","names":["useDefaultPacerOptions","Queuer"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport {
|
|
1
|
+
{"version":3,"file":"createQueuer.cjs","names":["useDefaultPacerOptions","Queuer","shallow"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } 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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\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 `queuer.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 items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = createQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\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 the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as SolidQueuerOptions<TValue, TSelected>\n const queuer = new Queuer(fn, mergedOptions) as unknown as SolidQueuer<\n TValue,\n TSelected\n >\n\n queuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(queuer.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n })\n })\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,aACd,IACA,UAAiD,EAAE,EACnD,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,SAAS,IAAIC,8BAAO,IAAI,cAAc;AAK5C,QAAO,YAAY,SAAS,UAAqB,OAG9C;EACD,MAAM,kDAAuB,OAAO,OAAO,MAAM,UAAU,EACzD,SAASC,+BACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,OAAO,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;AAEvE,kCAAmB;AACjB,gCAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAE/B,QAAO,MAAM;IAEf;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -36,8 +36,8 @@ interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'stor
|
|
|
36
36
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
37
37
|
/**
|
|
38
38
|
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
39
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
40
|
-
* Although, you can make the state reactive by using the `
|
|
39
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
40
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
41
41
|
*/
|
|
42
42
|
readonly store: Store<Readonly<QueuerState<TValue>>>;
|
|
43
43
|
}
|
|
@@ -36,8 +36,8 @@ interface SolidQueuer<TValue, TSelected = {}> extends Omit<Queuer<TValue>, 'stor
|
|
|
36
36
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
37
37
|
/**
|
|
38
38
|
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
39
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
40
|
-
* Although, you can make the state reactive by using the `
|
|
39
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
40
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
41
41
|
*/
|
|
42
42
|
readonly store: Store<Readonly<QueuerState<TValue>>>;
|
|
43
43
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
2
|
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { shallow, useSelector } from "@tanstack/solid-store";
|
|
4
4
|
import { Queuer } from "@tanstack/pacer/queuer";
|
|
5
5
|
|
|
6
6
|
//#region src/queuer/createQueuer.ts
|
|
@@ -112,10 +112,10 @@ function createQueuer(fn, options = {}, selector = () => ({})) {
|
|
|
112
112
|
};
|
|
113
113
|
const queuer = new Queuer(fn, mergedOptions);
|
|
114
114
|
queuer.Subscribe = function Subscribe(props) {
|
|
115
|
-
const selected =
|
|
115
|
+
const selected = useSelector(queuer.store, props.selector, { compare: shallow });
|
|
116
116
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
117
117
|
};
|
|
118
|
-
const state =
|
|
118
|
+
const state = useSelector(queuer.store, selector, { compare: shallow });
|
|
119
119
|
createEffect(() => {
|
|
120
120
|
onCleanup(() => {
|
|
121
121
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(queuer);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQueuer.js","names":[],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport {
|
|
1
|
+
{"version":3,"file":"createQueuer.js","names":[],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\nimport { shallow, useSelector } 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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuerOptions<\n TValue,\n TSelected = {},\n> extends QueuerOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the queuer instance.\n * When provided, replaces the default cleanup (stop); use it to call flush(), flushAsBatch(), stop(), add logging, etc.\n */\n onUnmount?: (queuer: SolidQueuer<TValue, TSelected>) => void\n}\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\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 `queuer.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 items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * ## Unmount behavior\n *\n * By default, the primitive stops the queuer when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending items instead:\n *\n * ```tsx\n * const queue = createQueuer(fn, {\n * started: true,\n * wait: 1000,\n * onUnmount: (q) => q.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\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 the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as SolidQueuerOptions<TValue, TSelected>\n const queuer = new Queuer(fn, mergedOptions) as unknown as SolidQueuer<\n TValue,\n TSelected\n >\n\n queuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(queuer.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(queuer.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(queuer)\n } else {\n queuer.stop()\n }\n })\n })\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,aACd,IACA,UAAiD,EAAE,EACnD,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,SAAS,IAAI,OAAO,IAAI,cAAc;AAK5C,QAAO,YAAY,SAAS,UAAqB,OAG9C;EACD,MAAM,WAAW,YAAY,OAAO,OAAO,MAAM,UAAU,EACzD,SAAS,SACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,OAAO,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAEvE,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,OAAO;OAE/B,QAAO,MAAM;IAEf;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -137,10 +137,10 @@ function createRateLimiter(fn, options, selector = () => ({})) {
|
|
|
137
137
|
};
|
|
138
138
|
const rateLimiter = new _tanstack_pacer_rate_limiter.RateLimiter(fn, mergedOptions);
|
|
139
139
|
rateLimiter.Subscribe = function Subscribe(props) {
|
|
140
|
-
const selected = (0, _tanstack_solid_store.
|
|
140
|
+
const selected = (0, _tanstack_solid_store.useSelector)(rateLimiter.store, props.selector, { compare: _tanstack_solid_store.shallow });
|
|
141
141
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
142
142
|
};
|
|
143
|
-
const state = (0, _tanstack_solid_store.
|
|
143
|
+
const state = (0, _tanstack_solid_store.useSelector)(rateLimiter.store, selector, { compare: _tanstack_solid_store.shallow });
|
|
144
144
|
(0, solid_js.createEffect)(() => {
|
|
145
145
|
(0, solid_js.onCleanup)(() => {
|
|
146
146
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(rateLimiter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.cjs","names":["useDefaultPacerOptions","RateLimiter"],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport {
|
|
1
|
+
{"version":3,"file":"createRateLimiter.cjs","names":["useDefaultPacerOptions","RateLimiter","shallow"],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } 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 RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\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 `rateLimiter.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 function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(rateLimiter.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(rateLimiter.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAIC,yCACtB,IACA,cACD;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,kDAAuB,YAAY,OAAO,MAAM,UAAU,EAC9D,SAASC,+BACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,YAAY,OAAO,UAAU,EAAE,SAASA,+BAAS,CAAC;AAE5E,kCAAmB;AACjB,gCAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,YAAY;IAEtC;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -37,8 +37,8 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
37
37
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
41
|
-
* Although, you can make the state reactive by using the `
|
|
40
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
42
|
*/
|
|
43
43
|
readonly store: Store<Readonly<RateLimiterState>>;
|
|
44
44
|
}
|
|
@@ -37,8 +37,8 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
|
|
|
37
37
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
41
|
-
* Although, you can make the state reactive by using the `
|
|
40
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
42
|
*/
|
|
43
43
|
readonly store: Store<Readonly<RateLimiterState>>;
|
|
44
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
2
|
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { shallow, useSelector } from "@tanstack/solid-store";
|
|
4
4
|
import { RateLimiter } from "@tanstack/pacer/rate-limiter";
|
|
5
5
|
|
|
6
6
|
//#region src/rate-limiter/createRateLimiter.ts
|
|
@@ -137,10 +137,10 @@ function createRateLimiter(fn, options, selector = () => ({})) {
|
|
|
137
137
|
};
|
|
138
138
|
const rateLimiter = new RateLimiter(fn, mergedOptions);
|
|
139
139
|
rateLimiter.Subscribe = function Subscribe(props) {
|
|
140
|
-
const selected =
|
|
140
|
+
const selected = useSelector(rateLimiter.store, props.selector, { compare: shallow });
|
|
141
141
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
142
142
|
};
|
|
143
|
-
const state =
|
|
143
|
+
const state = useSelector(rateLimiter.store, selector, { compare: shallow });
|
|
144
144
|
createEffect(() => {
|
|
145
145
|
onCleanup(() => {
|
|
146
146
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(rateLimiter);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport {
|
|
1
|
+
{"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } 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 RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiterOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends RateLimiterOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the rate limiter instance.\n * When provided, replaces the default cleanup; use it to call reset(), add logging, etc.\n */\n onUnmount?: (rateLimiter: SolidRateLimiter<TFn, TSelected>) => void\n}\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\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 `rateLimiter.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 function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidRateLimiterOptions<TFn, TSelected>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as SolidRateLimiterOptions<TFn, TSelected>\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(rateLimiter.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(rateLimiter.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(rateLimiter)\n }\n })\n })\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwLA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAClC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,cAAc,IAAI,YACtB,IACA,cACD;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,YAAY,YAAY,OAAO,MAAM,UAAU,EAC9D,SAAS,SACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,YAAY,OAAO,UAAU,EAAE,SAAS,SAAS,CAAC;AAE5E,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,YAAY;IAEtC;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -111,10 +111,10 @@ function createThrottler(fn, options, selector = () => ({})) {
|
|
|
111
111
|
};
|
|
112
112
|
const asyncThrottler = new _tanstack_pacer_throttler.Throttler(fn, mergedOptions);
|
|
113
113
|
asyncThrottler.Subscribe = function Subscribe(props) {
|
|
114
|
-
const selected = (0, _tanstack_solid_store.
|
|
114
|
+
const selected = (0, _tanstack_solid_store.useSelector)(asyncThrottler.store, props.selector, { compare: _tanstack_solid_store.shallow });
|
|
115
115
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
116
116
|
};
|
|
117
|
-
const state = (0, _tanstack_solid_store.
|
|
117
|
+
const state = (0, _tanstack_solid_store.useSelector)(asyncThrottler.store, selector, { compare: _tanstack_solid_store.shallow });
|
|
118
118
|
(0, solid_js.createEffect)(() => {
|
|
119
119
|
(0, solid_js.onCleanup)(() => {
|
|
120
120
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncThrottler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottler.cjs","names":["useDefaultPacerOptions","Throttler"],"sources":["../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, onCleanup } from 'solid-js'\nimport {
|
|
1
|
+
{"version":3,"file":"createThrottler.cjs","names":["useDefaultPacerOptions","Throttler","shallow"],"sources":["../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } 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 ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface SolidThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: SolidThrottler<TFn, TSelected>) => void\n}\n\nexport interface SolidThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the throttler state.\n *\n * This is useful for tracking specific parts of the throttler state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\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 `throttler.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 throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\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 throttler = createThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n *\n * // Opt-in to track isPending changes at hook level (optimized for loading states)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const throttler = createThrottler(\n * setValue,\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * lastExecutionTime: state.lastExecutionTime,\n * nextExecutionTime: state.nextExecutionTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = throttler.state();\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().throttler,\n ...options,\n } as SolidThrottlerOptions<TFn, TSelected>\n const asyncThrottler = new Throttler<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidThrottler<TFn, TSelected>\n\n asyncThrottler.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncThrottler.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(asyncThrottler.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncThrottler)\n } else {\n asyncThrottler.cancel()\n }\n })\n })\n\n return {\n ...asyncThrottler,\n state,\n } as SolidThrottler<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,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,kDAAuB,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,+BACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,eAAe,OAAO,UAAU,EACxD,SAASA,+BACV,CAAC;AAEF,kCAAmB;AACjB,gCAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,eAAe;OAEvC,gBAAe,QAAQ;IAEzB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -37,8 +37,8 @@ interface SolidThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<T
|
|
|
37
37
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
41
|
-
* Although, you can make the state reactive by using the `
|
|
40
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
42
|
*/
|
|
43
43
|
readonly store: Store<Readonly<ThrottlerState<TFn>>>;
|
|
44
44
|
}
|
|
@@ -37,8 +37,8 @@ interface SolidThrottler<TFn extends AnyFunction, TSelected = {}> extends Omit<T
|
|
|
37
37
|
readonly state: Accessor<Readonly<TSelected>>;
|
|
38
38
|
/**
|
|
39
39
|
* @deprecated Use `throttler.state` instead of `throttler.store.state` if you want to read reactive state.
|
|
40
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
41
|
-
* Although, you can make the state reactive by using the `
|
|
40
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
41
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
42
42
|
*/
|
|
43
43
|
readonly store: Store<Readonly<ThrottlerState<TFn>>>;
|
|
44
44
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useDefaultPacerOptions } from "../provider/PacerProvider.js";
|
|
2
2
|
import { createEffect, onCleanup } from "solid-js";
|
|
3
|
-
import {
|
|
3
|
+
import { shallow, useSelector } from "@tanstack/solid-store";
|
|
4
4
|
import { Throttler } from "@tanstack/pacer/throttler";
|
|
5
5
|
|
|
6
6
|
//#region src/throttler/createThrottler.ts
|
|
@@ -111,10 +111,10 @@ function createThrottler(fn, options, selector = () => ({})) {
|
|
|
111
111
|
};
|
|
112
112
|
const asyncThrottler = new Throttler(fn, mergedOptions);
|
|
113
113
|
asyncThrottler.Subscribe = function Subscribe(props) {
|
|
114
|
-
const selected =
|
|
114
|
+
const selected = useSelector(asyncThrottler.store, props.selector, { compare: shallow });
|
|
115
115
|
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
116
116
|
};
|
|
117
|
-
const state =
|
|
117
|
+
const state = useSelector(asyncThrottler.store, selector, { compare: shallow });
|
|
118
118
|
createEffect(() => {
|
|
119
119
|
onCleanup(() => {
|
|
120
120
|
if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncThrottler);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createThrottler.js","names":[],"sources":["../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, onCleanup } from 'solid-js'\nimport {
|
|
1
|
+
{"version":3,"file":"createThrottler.js","names":[],"sources":["../../src/throttler/createThrottler.ts"],"sourcesContent":["import { Throttler } from '@tanstack/pacer/throttler'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } 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 ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\nexport interface SolidThrottlerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends ThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: SolidThrottler<TFn, TSelected>) => void\n}\n\nexport interface SolidThrottler<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Throttler<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the throttler state.\n *\n * This is useful for tracking specific parts of the throttler state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the throttler state changes\n *\n * Use this instead of `throttler.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `throttler.state` instead of `throttler.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 `useSelector` hook internally.\n * Although, you can make the state reactive by using the `useSelector` in your own usage.\n */\n readonly store: Store<Readonly<ThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates a `Throttler` instance that limits how often the provided function can execute.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that\n * you can integrate with any state management solution (createSignal, Redux, Zustand, Jotai, etc). For a simpler and higher-level hook that\n * integrates directly with Solid's createSignal, see createThrottledSignal.\n *\n * Throttling ensures a function executes at most once within a specified time window,\n * regardless of how many times it is called. This is useful for rate-limiting\n * expensive operations or UI updates.\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 `throttler.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 throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Timestamp of the last execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\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 throttler = createThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const throttler = createThrottler(setValue, { wait: 1000 });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Loading...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n *\n * // Opt-in to track isPending changes at hook level (optimized for loading states)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const throttler = createThrottler(\n * setValue,\n * { wait: 1000 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const throttler = createThrottler(\n * setValue,\n * {\n * wait: 2000,\n * leading: true, // Execute immediately on first call\n * trailing: false // Skip trailing edge updates\n * },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * lastExecutionTime: state.lastExecutionTime,\n * nextExecutionTime: state.nextExecutionTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, executionCount } = throttler.state();\n * ```\n */\nexport function createThrottler<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidThrottlerOptions<TFn, TSelected>,\n selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().throttler,\n ...options,\n } as SolidThrottlerOptions<TFn, TSelected>\n const asyncThrottler = new Throttler<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidThrottler<TFn, TSelected>\n\n asyncThrottler.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: ThrottlerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncThrottler.store, props.selector, {\n compare: shallow,\n })\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useSelector(asyncThrottler.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncThrottler)\n } else {\n asyncThrottler.cancel()\n }\n })\n })\n\n return {\n ...asyncThrottler,\n state,\n } as SolidThrottler<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8JA,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,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,SACV,CAAC;AAEF,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,SACV,CAAC;AAEF,oBAAmB;AACjB,kBAAgB;AACd,OAAI,cAAc,UAChB,eAAc,UAAU,eAAe;OAEvC,gBAAe,QAAQ;IAEzB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/solid-pacer",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "Utilities for debouncing and throttling functions in Solid.",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -94,12 +94,12 @@
|
|
|
94
94
|
"src"
|
|
95
95
|
],
|
|
96
96
|
"dependencies": {
|
|
97
|
-
"@tanstack/solid-store": "^0.
|
|
98
|
-
"@tanstack/pacer": "0.
|
|
97
|
+
"@tanstack/solid-store": "^0.11.0",
|
|
98
|
+
"@tanstack/pacer": "0.21.0"
|
|
99
99
|
},
|
|
100
100
|
"devDependencies": {
|
|
101
|
-
"solid-js": "^1.9.
|
|
102
|
-
"vite-plugin-solid": "^2.11.
|
|
101
|
+
"solid-js": "^1.9.12",
|
|
102
|
+
"vite-plugin-solid": "^2.11.12"
|
|
103
103
|
},
|
|
104
104
|
"peerDependencies": {
|
|
105
105
|
"solid-js": ">=1.9.5"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncBatcher } from '@tanstack/pacer/async-batcher'
|
|
2
|
-
import {
|
|
2
|
+
import { shallow, useSelector } from '@tanstack/solid-store'
|
|
3
3
|
import { createEffect, onCleanup } from 'solid-js'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/solid-store'
|
|
@@ -49,8 +49,8 @@ export interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<
|
|
|
49
49
|
readonly state: Accessor<Readonly<TSelected>>
|
|
50
50
|
/**
|
|
51
51
|
* @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
|
|
52
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
53
|
-
* Although, you can make the state reactive by using the `
|
|
52
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
53
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
54
54
|
*/
|
|
55
55
|
readonly store: Store<Readonly<AsyncBatcherState<TValue>>>
|
|
56
56
|
}
|
|
@@ -205,14 +205,16 @@ export function createAsyncBatcher<TValue, TSelected = {}>(
|
|
|
205
205
|
selector: (state: AsyncBatcherState<TValue>) => TSelected
|
|
206
206
|
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element
|
|
207
207
|
}) {
|
|
208
|
-
const selected =
|
|
208
|
+
const selected = useSelector(asyncBatcher.store, props.selector, {
|
|
209
|
+
compare: shallow,
|
|
210
|
+
})
|
|
209
211
|
|
|
210
212
|
return typeof props.children === 'function'
|
|
211
213
|
? props.children(selected)
|
|
212
214
|
: props.children
|
|
213
215
|
}
|
|
214
216
|
|
|
215
|
-
const state =
|
|
217
|
+
const state = useSelector(asyncBatcher.store, selector, { compare: shallow })
|
|
216
218
|
|
|
217
219
|
createEffect(() => {
|
|
218
220
|
onCleanup(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'
|
|
2
|
-
import {
|
|
2
|
+
import { shallow, useSelector } from '@tanstack/solid-store'
|
|
3
3
|
import { createEffect, onCleanup } from 'solid-js'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/solid-store'
|
|
@@ -50,8 +50,8 @@ export interface SolidAsyncDebouncer<
|
|
|
50
50
|
readonly state: Accessor<Readonly<TSelected>>
|
|
51
51
|
/**
|
|
52
52
|
* @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
|
|
53
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
54
|
-
* Although, you can make the state reactive by using the `
|
|
53
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
54
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
55
55
|
*/
|
|
56
56
|
readonly store: Store<Readonly<AsyncDebouncerState<TFn>>>
|
|
57
57
|
}
|
|
@@ -194,14 +194,18 @@ export function createAsyncDebouncer<
|
|
|
194
194
|
selector: (state: AsyncDebouncerState<TFn>) => TSelected
|
|
195
195
|
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element
|
|
196
196
|
}) {
|
|
197
|
-
const selected =
|
|
197
|
+
const selected = useSelector(asyncDebouncer.store, props.selector, {
|
|
198
|
+
compare: shallow,
|
|
199
|
+
})
|
|
198
200
|
|
|
199
201
|
return typeof props.children === 'function'
|
|
200
202
|
? props.children(selected)
|
|
201
203
|
: props.children
|
|
202
204
|
}
|
|
203
205
|
|
|
204
|
-
const state =
|
|
206
|
+
const state = useSelector(asyncDebouncer.store, selector, {
|
|
207
|
+
compare: shallow,
|
|
208
|
+
})
|
|
205
209
|
|
|
206
210
|
createEffect(() => {
|
|
207
211
|
onCleanup(() => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncQueuer } from '@tanstack/pacer/async-queuer'
|
|
2
|
-
import {
|
|
2
|
+
import { shallow, useSelector } from '@tanstack/solid-store'
|
|
3
3
|
import { createEffect, onCleanup } from 'solid-js'
|
|
4
4
|
import { useDefaultPacerOptions } from '../provider/PacerProvider'
|
|
5
5
|
import type { Store } from '@tanstack/solid-store'
|
|
@@ -49,8 +49,8 @@ export interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<
|
|
|
49
49
|
readonly state: Accessor<Readonly<TSelected>>
|
|
50
50
|
/**
|
|
51
51
|
* @deprecated Use `queuer.state` instead of `queuer.store.state` if you want to read reactive state.
|
|
52
|
-
* The state on the store object is not reactive, as it has not been wrapped in a `
|
|
53
|
-
* Although, you can make the state reactive by using the `
|
|
52
|
+
* The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
|
|
53
|
+
* Although, you can make the state reactive by using the `useSelector` in your own usage.
|
|
54
54
|
*/
|
|
55
55
|
readonly store: Store<Readonly<AsyncQueuerState<TValue>>>
|
|
56
56
|
}
|
|
@@ -197,14 +197,16 @@ export function createAsyncQueuer<TValue, TSelected = {}>(
|
|
|
197
197
|
selector: (state: AsyncQueuerState<TValue>) => TSelected
|
|
198
198
|
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element
|
|
199
199
|
}) {
|
|
200
|
-
const selected =
|
|
200
|
+
const selected = useSelector(asyncQueuer.store, props.selector, {
|
|
201
|
+
compare: shallow,
|
|
202
|
+
})
|
|
201
203
|
|
|
202
204
|
return typeof props.children === 'function'
|
|
203
205
|
? props.children(selected)
|
|
204
206
|
: props.children
|
|
205
207
|
}
|
|
206
208
|
|
|
207
|
-
const state =
|
|
209
|
+
const state = useSelector(asyncQueuer.store, selector, { compare: shallow })
|
|
208
210
|
|
|
209
211
|
createEffect(() => {
|
|
210
212
|
onCleanup(() => {
|