@tanstack/solid-pacer 0.17.0 → 0.18.1
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 +26 -12
- package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
- package/dist/async-batcher/createAsyncBatcher.d.cts +36 -9
- package/dist/async-batcher/createAsyncBatcher.d.ts +36 -9
- package/dist/async-batcher/createAsyncBatcher.js +22 -8
- package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
- package/dist/async-batcher/index.cjs +3 -3
- package/dist/async-debouncer/createAsyncDebouncer.cjs +26 -12
- package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
- package/dist/async-debouncer/createAsyncDebouncer.d.cts +36 -9
- package/dist/async-debouncer/createAsyncDebouncer.d.ts +36 -9
- package/dist/async-debouncer/createAsyncDebouncer.js +22 -8
- package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
- package/dist/async-debouncer/index.cjs +3 -3
- package/dist/async-queuer/createAsyncQueuer.cjs +26 -12
- package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
- package/dist/async-queuer/createAsyncQueuer.d.cts +36 -9
- package/dist/async-queuer/createAsyncQueuer.d.ts +36 -9
- package/dist/async-queuer/createAsyncQueuer.js +22 -8
- package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
- package/dist/async-queuer/index.cjs +3 -3
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +89 -30
- package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +99 -27
- package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +99 -27
- package/dist/async-rate-limiter/createAsyncRateLimiter.js +85 -26
- package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
- package/dist/async-rate-limiter/index.cjs +3 -3
- package/dist/async-throttler/createAsyncThrottler.cjs +26 -12
- package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
- package/dist/async-throttler/createAsyncThrottler.d.cts +36 -9
- package/dist/async-throttler/createAsyncThrottler.d.ts +36 -9
- package/dist/async-throttler/createAsyncThrottler.js +22 -8
- package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
- package/dist/async-throttler/index.cjs +3 -3
- package/dist/batcher/createBatcher.cjs +26 -12
- package/dist/batcher/createBatcher.cjs.map +1 -1
- package/dist/batcher/createBatcher.d.cts +36 -9
- package/dist/batcher/createBatcher.d.ts +36 -9
- package/dist/batcher/createBatcher.js +22 -8
- package/dist/batcher/createBatcher.js.map +1 -1
- package/dist/batcher/index.cjs +3 -3
- package/dist/debouncer/createDebouncer.cjs +27 -13
- package/dist/debouncer/createDebouncer.cjs.map +1 -1
- package/dist/debouncer/createDebouncer.d.cts +37 -10
- package/dist/debouncer/createDebouncer.d.ts +37 -10
- package/dist/debouncer/createDebouncer.js +23 -9
- package/dist/debouncer/createDebouncer.js.map +1 -1
- package/dist/debouncer/index.cjs +3 -3
- package/dist/index.cjs +3 -3
- package/dist/queuer/createQueuedSignal.cjs +8 -8
- package/dist/queuer/createQueuedSignal.cjs.map +1 -1
- package/dist/queuer/createQueuedSignal.d.cts +8 -8
- package/dist/queuer/createQueuedSignal.d.ts +8 -8
- package/dist/queuer/createQueuedSignal.js +8 -8
- package/dist/queuer/createQueuedSignal.js.map +1 -1
- package/dist/queuer/createQueuer.cjs +26 -12
- package/dist/queuer/createQueuer.cjs.map +1 -1
- package/dist/queuer/createQueuer.d.cts +36 -9
- package/dist/queuer/createQueuer.d.ts +36 -9
- package/dist/queuer/createQueuer.js +22 -8
- package/dist/queuer/createQueuer.js.map +1 -1
- package/dist/queuer/index.cjs +3 -3
- package/dist/rate-limiter/createRateLimiter.cjs +78 -23
- package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
- package/dist/rate-limiter/createRateLimiter.d.cts +88 -20
- package/dist/rate-limiter/createRateLimiter.d.ts +88 -20
- package/dist/rate-limiter/createRateLimiter.js +74 -19
- package/dist/rate-limiter/createRateLimiter.js.map +1 -1
- package/dist/rate-limiter/index.cjs +3 -3
- package/dist/throttler/createThrottledSignal.cjs +1 -1
- package/dist/throttler/createThrottledSignal.cjs.map +1 -1
- package/dist/throttler/createThrottledSignal.d.cts +1 -1
- package/dist/throttler/createThrottledSignal.d.ts +1 -1
- package/dist/throttler/createThrottledSignal.js +1 -1
- package/dist/throttler/createThrottledSignal.js.map +1 -1
- package/dist/throttler/createThrottledValue.cjs +1 -1
- package/dist/throttler/createThrottledValue.cjs.map +1 -1
- package/dist/throttler/createThrottledValue.d.cts +1 -1
- package/dist/throttler/createThrottledValue.d.ts +1 -1
- package/dist/throttler/createThrottledValue.js +1 -1
- package/dist/throttler/createThrottledValue.js.map +1 -1
- package/dist/throttler/createThrottler.cjs +34 -13
- package/dist/throttler/createThrottler.cjs.map +1 -1
- package/dist/throttler/createThrottler.d.cts +44 -10
- package/dist/throttler/createThrottler.d.ts +44 -10
- package/dist/throttler/createThrottler.js +30 -9
- package/dist/throttler/createThrottler.js.map +1 -1
- package/dist/throttler/index.cjs +3 -3
- package/dist/types/index.cjs +3 -3
- package/dist/utils/index.cjs +3 -3
- package/package.json +2 -2
- package/src/async-batcher/createAsyncBatcher.ts +51 -10
- package/src/async-debouncer/createAsyncDebouncer.ts +51 -10
- package/src/async-queuer/createAsyncQueuer.ts +51 -10
- package/src/async-rate-limiter/createAsyncRateLimiter.ts +114 -28
- package/src/async-throttler/createAsyncThrottler.ts +51 -10
- package/src/batcher/createBatcher.ts +51 -10
- package/src/debouncer/createDebouncer.ts +52 -11
- package/src/queuer/createQueuedSignal.ts +8 -8
- package/src/queuer/createQueuer.ts +51 -10
- package/src/rate-limiter/createRateLimiter.ts +103 -21
- package/src/throttler/createThrottledSignal.ts +1 -1
- package/src/throttler/createThrottledValue.ts +1 -1
- package/src/throttler/createThrottler.ts +59 -11
|
@@ -1,10 +1,27 @@
|
|
|
1
|
-
import { Accessor } from "solid-js";
|
|
1
|
+
import { Accessor, JSX } from "solid-js";
|
|
2
2
|
import { Store } from "@tanstack/solid-store";
|
|
3
3
|
import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
|
|
4
4
|
import { AnyAsyncFunction } from "@tanstack/pacer/types";
|
|
5
5
|
|
|
6
6
|
//#region src/async-debouncer/createAsyncDebouncer.d.ts
|
|
7
7
|
interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
|
|
8
|
+
/**
|
|
9
|
+
* A Solid component that allows you to subscribe to the debouncer state.
|
|
10
|
+
*
|
|
11
|
+
* This is useful for tracking specific parts of the debouncer state
|
|
12
|
+
* deep in your component tree without needing to pass a selector to the hook.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
|
|
16
|
+
* {(state) => (
|
|
17
|
+
* <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
|
|
18
|
+
* )}
|
|
19
|
+
* </debouncer.Subscribe>
|
|
20
|
+
*/
|
|
21
|
+
Subscribe: <TSelected>(props: {
|
|
22
|
+
selector: (state: AsyncDebouncerState<TFn>) => TSelected;
|
|
23
|
+
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
24
|
+
}) => JSX.Element;
|
|
8
25
|
/**
|
|
9
26
|
* Reactive state that will be updated when the debouncer state changes
|
|
10
27
|
*
|
|
@@ -44,14 +61,24 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
44
61
|
*
|
|
45
62
|
* ## State Management and Selector
|
|
46
63
|
*
|
|
47
|
-
* The hook uses TanStack Store for reactive state management.
|
|
48
|
-
*
|
|
49
|
-
*
|
|
64
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
65
|
+
* in two ways:
|
|
66
|
+
*
|
|
67
|
+
* **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
68
|
+
*
|
|
69
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
70
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
71
|
+
* in child components.
|
|
72
|
+
*
|
|
73
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
74
|
+
*
|
|
75
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
76
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
77
|
+
* state changes occur.
|
|
50
78
|
*
|
|
51
79
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
52
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
53
|
-
* full control over when your component
|
|
54
|
-
* component re-render when the selected state values change.
|
|
80
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
81
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
55
82
|
*
|
|
56
83
|
* Available state properties:
|
|
57
84
|
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
@@ -75,7 +102,7 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
75
102
|
* { wait: 500 }
|
|
76
103
|
* );
|
|
77
104
|
*
|
|
78
|
-
* // Opt-in to
|
|
105
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
79
106
|
* const debouncer = createAsyncDebouncer(
|
|
80
107
|
* async (query: string) => {
|
|
81
108
|
* const results = await api.search(query);
|
|
@@ -85,7 +112,7 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
|
|
|
85
112
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
86
113
|
* );
|
|
87
114
|
*
|
|
88
|
-
* // Opt-in to
|
|
115
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
89
116
|
* const debouncer = createAsyncDebouncer(
|
|
90
117
|
* async (searchTerm) => {
|
|
91
118
|
* const data = await searchAPI(searchTerm);
|
|
@@ -30,14 +30,24 @@ import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
|
30
30
|
*
|
|
31
31
|
* ## State Management and Selector
|
|
32
32
|
*
|
|
33
|
-
* The hook uses TanStack Store for reactive state management.
|
|
34
|
-
*
|
|
35
|
-
*
|
|
33
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
34
|
+
* in two ways:
|
|
35
|
+
*
|
|
36
|
+
* **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
37
|
+
*
|
|
38
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
39
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
40
|
+
* in child components.
|
|
41
|
+
*
|
|
42
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
43
|
+
*
|
|
44
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
45
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
46
|
+
* state changes occur.
|
|
36
47
|
*
|
|
37
48
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
38
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
39
|
-
* full control over when your component
|
|
40
|
-
* component re-render when the selected state values change.
|
|
49
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
50
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
41
51
|
*
|
|
42
52
|
* Available state properties:
|
|
43
53
|
* - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
|
|
@@ -61,7 +71,7 @@ import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
|
61
71
|
* { wait: 500 }
|
|
62
72
|
* );
|
|
63
73
|
*
|
|
64
|
-
* // Opt-in to
|
|
74
|
+
* // Opt-in to track isPending or isExecuting changes (optimized for loading states)
|
|
65
75
|
* const debouncer = createAsyncDebouncer(
|
|
66
76
|
* async (query: string) => {
|
|
67
77
|
* const results = await api.search(query);
|
|
@@ -71,7 +81,7 @@ import { AsyncDebouncer } from "@tanstack/pacer/async-debouncer";
|
|
|
71
81
|
* (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
|
|
72
82
|
* );
|
|
73
83
|
*
|
|
74
|
-
* // Opt-in to
|
|
84
|
+
* // Opt-in to track error state changes (optimized for error handling)
|
|
75
85
|
* const debouncer = createAsyncDebouncer(
|
|
76
86
|
* async (searchTerm) => {
|
|
77
87
|
* const data = await searchAPI(searchTerm);
|
|
@@ -97,6 +107,10 @@ function createAsyncDebouncer(fn, options, selector = () => ({})) {
|
|
|
97
107
|
...useDefaultPacerOptions().asyncDebouncer,
|
|
98
108
|
...options
|
|
99
109
|
});
|
|
110
|
+
asyncDebouncer.Subscribe = function Subscribe(props) {
|
|
111
|
+
const selected = useStore(asyncDebouncer.store, props.selector);
|
|
112
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
113
|
+
};
|
|
100
114
|
const state = useStore(asyncDebouncer.store, selector);
|
|
101
115
|
createEffect(() => {
|
|
102
116
|
onCleanup(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\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 } from 'solid-js'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing\n * or input changes where you only want to execute the handler after the events have stopped occurring.\n *\n * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until\n * the function stops being called for the specified delay period.\n *\n * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the debounced function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and debouncer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncDebouncer instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
1
|
+
{"version":3,"file":"createAsyncDebouncer.js","names":[],"sources":["../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\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 {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<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, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncDebouncerState<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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing\n * or input changes where you only want to execute the handler after the events have stopped occurring.\n *\n * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until\n * the function stops being called for the specified delay period.\n *\n * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the debounced function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and debouncer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncDebouncer instance\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 * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastResult`: The result from the most recent successful execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const debouncer = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const debouncer = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * return data;\n * },\n * {\n * wait: 300,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = debouncer.state();\n * ```\n */\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncDebouncerOptions<TFn>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncDebouncer,\n ...options,\n } as AsyncDebouncerOptions<TFn>\n\n const asyncDebouncer = new AsyncDebouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncDebouncerState<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 asyncDebouncer.cancel()\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidAsyncDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiJA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAI,eACzB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;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,kBAAe,QAAQ;IACvB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_createAsyncDebouncer = require('./createAsyncDebouncer.cjs');
|
|
2
2
|
|
|
3
3
|
exports.createAsyncDebouncer = require_createAsyncDebouncer.createAsyncDebouncer;
|
|
4
|
-
var
|
|
5
|
-
Object.keys(
|
|
4
|
+
var _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer");
|
|
5
|
+
Object.keys(_tanstack_pacer_async_debouncer).forEach(function (k) {
|
|
6
6
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function () { return
|
|
8
|
+
get: function () { return _tanstack_pacer_async_debouncer[k]; }
|
|
9
9
|
});
|
|
10
10
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_PacerProvider = require('../provider/PacerProvider.cjs');
|
|
2
|
-
let
|
|
3
|
-
let
|
|
2
|
+
let _tanstack_solid_store = require("@tanstack/solid-store");
|
|
3
|
+
let _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
4
4
|
|
|
5
5
|
//#region src/async-queuer/createAsyncQueuer.ts
|
|
6
6
|
/**
|
|
@@ -28,14 +28,24 @@ let __tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
|
28
28
|
*
|
|
29
29
|
* ## State Management and Selector
|
|
30
30
|
*
|
|
31
|
-
* The hook uses TanStack Store for reactive state management.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
32
|
+
* in two ways:
|
|
33
|
+
*
|
|
34
|
+
* **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
35
|
+
*
|
|
36
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
37
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
38
|
+
* in child components.
|
|
39
|
+
*
|
|
40
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
41
|
+
*
|
|
42
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
43
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
44
|
+
* state changes occur.
|
|
34
45
|
*
|
|
35
46
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
36
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
37
|
-
* full control over when your component
|
|
38
|
-
* component re-render when the selected state values change.
|
|
47
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
48
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
39
49
|
*
|
|
40
50
|
* Available state properties:
|
|
41
51
|
* - `activeItems`: Array of items currently being processed
|
|
@@ -65,7 +75,7 @@ let __tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
|
65
75
|
* }
|
|
66
76
|
* });
|
|
67
77
|
*
|
|
68
|
-
* // Opt-in to
|
|
78
|
+
* // Opt-in to track queue state changes (optimized for UI updates)
|
|
69
79
|
* const asyncQueuer = createAsyncQueuer(
|
|
70
80
|
* async (item) => await fetchData(item),
|
|
71
81
|
* { concurrency: 2, started: true },
|
|
@@ -76,7 +86,7 @@ let __tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
|
76
86
|
* })
|
|
77
87
|
* );
|
|
78
88
|
*
|
|
79
|
-
* // Opt-in to
|
|
89
|
+
* // Opt-in to track processing metrics changes (optimized for tracking progress)
|
|
80
90
|
* const asyncQueuer = createAsyncQueuer(
|
|
81
91
|
* async (item) => await fetchData(item),
|
|
82
92
|
* { concurrency: 2, started: true },
|
|
@@ -98,11 +108,15 @@ let __tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
|
98
108
|
* ```
|
|
99
109
|
*/
|
|
100
110
|
function createAsyncQueuer(fn, options = {}, selector = () => ({})) {
|
|
101
|
-
const asyncQueuer = new
|
|
111
|
+
const asyncQueuer = new _tanstack_pacer_async_queuer.AsyncQueuer(fn, {
|
|
102
112
|
...require_PacerProvider.useDefaultPacerOptions().asyncQueuer,
|
|
103
113
|
...options
|
|
104
114
|
});
|
|
105
|
-
|
|
115
|
+
asyncQueuer.Subscribe = function Subscribe(props) {
|
|
116
|
+
const selected = (0, _tanstack_solid_store.useStore)(asyncQueuer.store, props.selector);
|
|
117
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
118
|
+
};
|
|
119
|
+
const state = (0, _tanstack_solid_store.useStore)(asyncQueuer.store, selector);
|
|
106
120
|
return {
|
|
107
121
|
...asyncQueuer,
|
|
108
122
|
state
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncQueuer.cjs","names":["AsyncQueuer","useDefaultPacerOptions"],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\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 `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
1
|
+
{"version":3,"file":"createAsyncQueuer.cjs","names":["AsyncQueuer","useDefaultPacerOptions"],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\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 {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<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) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>\n * {(state) => (\n * <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncQueuerState<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 `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\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 * - `activeItems`: Array of items currently being processed\n * - `errorCount`: Number of items that failed processing\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `pendingItems`: Array of items waiting to be processed\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n * - `settleCount`: Number of items that have completed processing (successful or failed)\n * - `successCount`: Number of items that were processed successfully\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncQueuer = createAsyncQueuer(async (item) => {\n * // process item\n * return await fetchData(item);\n * }, {\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Opt-in to track queue state changes (optimized for UI updates)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * pendingItems: state.pendingItems,\n * activeItems: state.activeItems,\n * isRunning: state.isRunning\n * })\n * );\n *\n * // Opt-in to track processing metrics changes (optimized for tracking progress)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * successCount: state.successCount,\n * errorCount: state.errorCount,\n * settleCount: state.settleCount\n * })\n * );\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { pendingItems, activeItems } = asyncQueuer.state();\n * ```\n */\nexport function createAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncQueuer,\n ...options,\n } as AsyncQueuerOptions<TValue>\n\n const asyncQueuer = new AsyncQueuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncQueuer<TValue, TSelected>\n\n asyncQueuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncQueuer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncQueuer.store, selector)\n\n return {\n ...asyncQueuer,\n state,\n } as SolidAsyncQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqJA,SAAgB,kBACd,IACA,UAAsC,EAAE,EACxC,kBACG,EAAE,GACgC;CAMrC,MAAM,cAAc,IAAIA,yCACtB,IANoB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,+CAAoB,YAAY,OAAO,MAAM,SAAS;AAE5D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,YAAY,OAAO,SAAS;AAEnD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,9 +1,26 @@
|
|
|
1
1
|
import { Store } from "@tanstack/solid-store";
|
|
2
|
-
import { Accessor } from "solid-js";
|
|
2
|
+
import { Accessor, JSX } from "solid-js";
|
|
3
3
|
import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
|
|
4
4
|
|
|
5
5
|
//#region src/async-queuer/createAsyncQueuer.d.ts
|
|
6
6
|
interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* A Solid component that allows you to subscribe to the queuer state.
|
|
9
|
+
*
|
|
10
|
+
* This is useful for tracking specific parts of the queuer state
|
|
11
|
+
* deep in your component tree without needing to pass a selector to the hook.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <queuer.Subscribe selector={(state) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>
|
|
15
|
+
* {(state) => (
|
|
16
|
+
* <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>
|
|
17
|
+
* )}
|
|
18
|
+
* </queuer.Subscribe>
|
|
19
|
+
*/
|
|
20
|
+
Subscribe: <TSelected>(props: {
|
|
21
|
+
selector: (state: AsyncQueuerState<TValue>) => TSelected;
|
|
22
|
+
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
23
|
+
}) => JSX.Element;
|
|
7
24
|
/**
|
|
8
25
|
* Reactive state that will be updated when the queuer state changes
|
|
9
26
|
*
|
|
@@ -42,14 +59,24 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
42
59
|
*
|
|
43
60
|
* ## State Management and Selector
|
|
44
61
|
*
|
|
45
|
-
* The hook uses TanStack Store for reactive state management.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
62
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
63
|
+
* in two ways:
|
|
64
|
+
*
|
|
65
|
+
* **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
66
|
+
*
|
|
67
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
68
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
69
|
+
* in child components.
|
|
70
|
+
*
|
|
71
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
72
|
+
*
|
|
73
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
74
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
75
|
+
* state changes occur.
|
|
48
76
|
*
|
|
49
77
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
50
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
51
|
-
* full control over when your component
|
|
52
|
-
* component re-render when the selected state values change.
|
|
78
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
79
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
53
80
|
*
|
|
54
81
|
* Available state properties:
|
|
55
82
|
* - `activeItems`: Array of items currently being processed
|
|
@@ -79,7 +106,7 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
79
106
|
* }
|
|
80
107
|
* });
|
|
81
108
|
*
|
|
82
|
-
* // Opt-in to
|
|
109
|
+
* // Opt-in to track queue state changes (optimized for UI updates)
|
|
83
110
|
* const asyncQueuer = createAsyncQueuer(
|
|
84
111
|
* async (item) => await fetchData(item),
|
|
85
112
|
* { concurrency: 2, started: true },
|
|
@@ -90,7 +117,7 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
90
117
|
* })
|
|
91
118
|
* );
|
|
92
119
|
*
|
|
93
|
-
* // Opt-in to
|
|
120
|
+
* // Opt-in to track processing metrics changes (optimized for tracking progress)
|
|
94
121
|
* const asyncQueuer = createAsyncQueuer(
|
|
95
122
|
* async (item) => await fetchData(item),
|
|
96
123
|
* { concurrency: 2, started: true },
|
|
@@ -1,9 +1,26 @@
|
|
|
1
|
-
import { Accessor } from "solid-js";
|
|
1
|
+
import { Accessor, JSX } from "solid-js";
|
|
2
2
|
import { Store } from "@tanstack/solid-store";
|
|
3
3
|
import { AsyncQueuer, AsyncQueuerOptions, AsyncQueuerState } from "@tanstack/pacer/async-queuer";
|
|
4
4
|
|
|
5
5
|
//#region src/async-queuer/createAsyncQueuer.d.ts
|
|
6
6
|
interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TValue>, 'store'> {
|
|
7
|
+
/**
|
|
8
|
+
* A Solid component that allows you to subscribe to the queuer state.
|
|
9
|
+
*
|
|
10
|
+
* This is useful for tracking specific parts of the queuer state
|
|
11
|
+
* deep in your component tree without needing to pass a selector to the hook.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* <queuer.Subscribe selector={(state) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>
|
|
15
|
+
* {(state) => (
|
|
16
|
+
* <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>
|
|
17
|
+
* )}
|
|
18
|
+
* </queuer.Subscribe>
|
|
19
|
+
*/
|
|
20
|
+
Subscribe: <TSelected>(props: {
|
|
21
|
+
selector: (state: AsyncQueuerState<TValue>) => TSelected;
|
|
22
|
+
children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
|
|
23
|
+
}) => JSX.Element;
|
|
7
24
|
/**
|
|
8
25
|
* Reactive state that will be updated when the queuer state changes
|
|
9
26
|
*
|
|
@@ -42,14 +59,24 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
42
59
|
*
|
|
43
60
|
* ## State Management and Selector
|
|
44
61
|
*
|
|
45
|
-
* The hook uses TanStack Store for reactive state management.
|
|
46
|
-
*
|
|
47
|
-
*
|
|
62
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
63
|
+
* in two ways:
|
|
64
|
+
*
|
|
65
|
+
* **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
66
|
+
*
|
|
67
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
68
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
69
|
+
* in child components.
|
|
70
|
+
*
|
|
71
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
72
|
+
*
|
|
73
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
74
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
75
|
+
* state changes occur.
|
|
48
76
|
*
|
|
49
77
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
50
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
51
|
-
* full control over when your component
|
|
52
|
-
* component re-render when the selected state values change.
|
|
78
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
79
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
53
80
|
*
|
|
54
81
|
* Available state properties:
|
|
55
82
|
* - `activeItems`: Array of items currently being processed
|
|
@@ -79,7 +106,7 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
79
106
|
* }
|
|
80
107
|
* });
|
|
81
108
|
*
|
|
82
|
-
* // Opt-in to
|
|
109
|
+
* // Opt-in to track queue state changes (optimized for UI updates)
|
|
83
110
|
* const asyncQueuer = createAsyncQueuer(
|
|
84
111
|
* async (item) => await fetchData(item),
|
|
85
112
|
* { concurrency: 2, started: true },
|
|
@@ -90,7 +117,7 @@ interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<AsyncQueuer<TVal
|
|
|
90
117
|
* })
|
|
91
118
|
* );
|
|
92
119
|
*
|
|
93
|
-
* // Opt-in to
|
|
120
|
+
* // Opt-in to track processing metrics changes (optimized for tracking progress)
|
|
94
121
|
* const asyncQueuer = createAsyncQueuer(
|
|
95
122
|
* async (item) => await fetchData(item),
|
|
96
123
|
* { concurrency: 2, started: true },
|
|
@@ -28,14 +28,24 @@ import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
|
|
|
28
28
|
*
|
|
29
29
|
* ## State Management and Selector
|
|
30
30
|
*
|
|
31
|
-
* The hook uses TanStack Store for reactive state management.
|
|
32
|
-
*
|
|
33
|
-
*
|
|
31
|
+
* The hook uses TanStack Store for reactive state management. You can subscribe to state changes
|
|
32
|
+
* in two ways:
|
|
33
|
+
*
|
|
34
|
+
* **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
|
|
35
|
+
*
|
|
36
|
+
* Use the `Subscribe` component to subscribe to state changes deep in your component tree without
|
|
37
|
+
* needing to pass a selector to the hook. This is ideal when you want to subscribe to state
|
|
38
|
+
* in child components.
|
|
39
|
+
*
|
|
40
|
+
* **2. Using the `selector` parameter (For hook-level subscriptions)**
|
|
41
|
+
*
|
|
42
|
+
* The `selector` parameter allows you to specify which state changes will trigger reactive updates
|
|
43
|
+
* at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
|
|
44
|
+
* state changes occur.
|
|
34
45
|
*
|
|
35
46
|
* **By default, there will be no reactive state subscriptions** and you must opt-in to state
|
|
36
|
-
* tracking by providing a selector function. This prevents unnecessary
|
|
37
|
-
* full control over when your component
|
|
38
|
-
* component re-render when the selected state values change.
|
|
47
|
+
* tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
|
|
48
|
+
* updates and gives you full control over when your component tracks state changes.
|
|
39
49
|
*
|
|
40
50
|
* Available state properties:
|
|
41
51
|
* - `activeItems`: Array of items currently being processed
|
|
@@ -65,7 +75,7 @@ import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
|
|
|
65
75
|
* }
|
|
66
76
|
* });
|
|
67
77
|
*
|
|
68
|
-
* // Opt-in to
|
|
78
|
+
* // Opt-in to track queue state changes (optimized for UI updates)
|
|
69
79
|
* const asyncQueuer = createAsyncQueuer(
|
|
70
80
|
* async (item) => await fetchData(item),
|
|
71
81
|
* { concurrency: 2, started: true },
|
|
@@ -76,7 +86,7 @@ import { AsyncQueuer } from "@tanstack/pacer/async-queuer";
|
|
|
76
86
|
* })
|
|
77
87
|
* );
|
|
78
88
|
*
|
|
79
|
-
* // Opt-in to
|
|
89
|
+
* // Opt-in to track processing metrics changes (optimized for tracking progress)
|
|
80
90
|
* const asyncQueuer = createAsyncQueuer(
|
|
81
91
|
* async (item) => await fetchData(item),
|
|
82
92
|
* { concurrency: 2, started: true },
|
|
@@ -102,6 +112,10 @@ function createAsyncQueuer(fn, options = {}, selector = () => ({})) {
|
|
|
102
112
|
...useDefaultPacerOptions().asyncQueuer,
|
|
103
113
|
...options
|
|
104
114
|
});
|
|
115
|
+
asyncQueuer.Subscribe = function Subscribe(props) {
|
|
116
|
+
const selected = useStore(asyncQueuer.store, props.selector);
|
|
117
|
+
return typeof props.children === "function" ? props.children(selected) : props.children;
|
|
118
|
+
};
|
|
105
119
|
const state = useStore(asyncQueuer.store, selector);
|
|
106
120
|
return {
|
|
107
121
|
...asyncQueuer,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<TValue>,\n 'store'\n> {\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 `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
|
|
1
|
+
{"version":3,"file":"createAsyncQueuer.js","names":[],"sources":["../../src/async-queuer/createAsyncQueuer.ts"],"sourcesContent":["import { AsyncQueuer } from '@tanstack/pacer/async-queuer'\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 {\n AsyncQueuerOptions,\n AsyncQueuerState,\n} from '@tanstack/pacer/async-queuer'\n\nexport interface SolidAsyncQueuer<TValue, TSelected = {}> extends Omit<\n AsyncQueuer<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) => ({ pendingItems: state.pendingItems, activeItems: state.activeItems })}>\n * {(state) => (\n * <div>Pending: {state().pendingItems.length}, Active: {state().activeItems.length}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncQueuerState<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 `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<AsyncQueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncQueuer instance for managing an asynchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Priority queueing via `getPriority` or item `priority` property\n * - Configurable concurrency limit\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Pause/resume processing\n * - Task cancellation\n * - Item expiration\n * - Lifecycle callbacks for success, error, settled, items change, etc.\n * - All stateful properties (active items, pending items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * Tasks are processed concurrently up to the configured concurrency limit. When a task completes,\n * the next pending task is processed if the concurrency limit allows.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and queuer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncQueuer instance\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 * - `activeItems`: Array of items currently being processed\n * - `errorCount`: Number of items that failed processing\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `pendingItems`: Array of items waiting to be processed\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n * - `settleCount`: Number of items that have completed processing (successful or failed)\n * - `successCount`: Number of items that were processed successfully\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncQueuer = createAsyncQueuer(async (item) => {\n * // process item\n * return await fetchData(item);\n * }, {\n * initialItems: [],\n * concurrency: 2,\n * maxSize: 100,\n * started: false,\n * onSuccess: (result) => {\n * console.log('Item processed:', result);\n * },\n * onError: (error) => {\n * console.error('Processing failed:', error);\n * }\n * });\n *\n * // Opt-in to track queue state changes (optimized for UI updates)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * pendingItems: state.pendingItems,\n * activeItems: state.activeItems,\n * isRunning: state.isRunning\n * })\n * );\n *\n * // Opt-in to track processing metrics changes (optimized for tracking progress)\n * const asyncQueuer = createAsyncQueuer(\n * async (item) => await fetchData(item),\n * { concurrency: 2, started: true },\n * (state) => ({\n * successCount: state.successCount,\n * errorCount: state.errorCount,\n * settleCount: state.settleCount\n * })\n * );\n *\n * // Add items to queue\n * asyncQueuer.addItem(newItem);\n *\n * // Start processing\n * asyncQueuer.start();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { pendingItems, activeItems } = asyncQueuer.state();\n * ```\n */\nexport function createAsyncQueuer<TValue, TSelected = {}>(\n fn: (value: TValue) => Promise<any>,\n options: AsyncQueuerOptions<TValue> = {},\n selector: (state: AsyncQueuerState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncQueuer,\n ...options,\n } as AsyncQueuerOptions<TValue>\n\n const asyncQueuer = new AsyncQueuer<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncQueuer<TValue, TSelected>\n\n asyncQueuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncQueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncQueuer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncQueuer.store, selector)\n\n return {\n ...asyncQueuer,\n state,\n } as SolidAsyncQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqJA,SAAgB,kBACd,IACA,UAAsC,EAAE,EACxC,kBACG,EAAE,GACgC;CAMrC,MAAM,cAAc,IAAI,YACtB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,SAAS,YAAY,OAAO,MAAM,SAAS;AAE5D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,YAAY,OAAO,SAAS;AAEnD,QAAO;EACL,GAAG;EACH;EACD"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
const require_createAsyncQueuer = require('./createAsyncQueuer.cjs');
|
|
2
2
|
|
|
3
3
|
exports.createAsyncQueuer = require_createAsyncQueuer.createAsyncQueuer;
|
|
4
|
-
var
|
|
5
|
-
Object.keys(
|
|
4
|
+
var _tanstack_pacer_async_queuer = require("@tanstack/pacer/async-queuer");
|
|
5
|
+
Object.keys(_tanstack_pacer_async_queuer).forEach(function (k) {
|
|
6
6
|
if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
7
7
|
enumerable: true,
|
|
8
|
-
get: function () { return
|
|
8
|
+
get: function () { return _tanstack_pacer_async_queuer[k]; }
|
|
9
9
|
});
|
|
10
10
|
});
|