@tanstack/solid-pacer 0.22.0 → 0.23.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.
Files changed (170) hide show
  1. package/README.md +4 -4
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -9
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -11
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -11
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -12
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -13
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -14
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -4
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -4
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -6
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -8
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -4
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -6
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -13
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -4
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -9
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -6
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -6
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -8
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +23 -67
  39. package/dist/async-batcher/createAsyncBatcher.cjs +0 -166
  40. package/dist/async-batcher/createAsyncBatcher.cjs.map +0 -1
  41. package/dist/async-batcher/createAsyncBatcher.d.cts +0 -177
  42. package/dist/async-batcher/createAsyncBatcher.js.map +0 -1
  43. package/dist/async-batcher/index.cjs +0 -11
  44. package/dist/async-batcher/index.d.cts +0 -3
  45. package/dist/async-debouncer/createAsyncDebouncer.cjs +0 -151
  46. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +0 -1
  47. package/dist/async-debouncer/createAsyncDebouncer.d.cts +0 -163
  48. package/dist/async-debouncer/createAsyncDebouncer.js.map +0 -1
  49. package/dist/async-debouncer/index.cjs +0 -11
  50. package/dist/async-debouncer/index.d.cts +0 -3
  51. package/dist/async-queuer/createAsyncQueuer.cjs +0 -158
  52. package/dist/async-queuer/createAsyncQueuer.cjs.map +0 -1
  53. package/dist/async-queuer/createAsyncQueuer.d.cts +0 -169
  54. package/dist/async-queuer/createAsyncQueuer.js.map +0 -1
  55. package/dist/async-queuer/index.cjs +0 -11
  56. package/dist/async-queuer/index.d.cts +0 -3
  57. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +0 -193
  58. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +0 -1
  59. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +0 -208
  60. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +0 -1
  61. package/dist/async-rate-limiter/index.cjs +0 -11
  62. package/dist/async-rate-limiter/index.d.cts +0 -3
  63. package/dist/async-throttler/createAsyncThrottler.cjs +0 -151
  64. package/dist/async-throttler/createAsyncThrottler.cjs.map +0 -1
  65. package/dist/async-throttler/createAsyncThrottler.d.cts +0 -163
  66. package/dist/async-throttler/createAsyncThrottler.js.map +0 -1
  67. package/dist/async-throttler/index.cjs +0 -11
  68. package/dist/async-throttler/index.d.cts +0 -3
  69. package/dist/batcher/createBatcher.cjs +0 -132
  70. package/dist/batcher/createBatcher.cjs.map +0 -1
  71. package/dist/batcher/createBatcher.d.cts +0 -146
  72. package/dist/batcher/createBatcher.js.map +0 -1
  73. package/dist/batcher/index.cjs +0 -11
  74. package/dist/batcher/index.d.cts +0 -3
  75. package/dist/debouncer/createDebouncedSignal.cjs +0 -88
  76. package/dist/debouncer/createDebouncedSignal.cjs.map +0 -1
  77. package/dist/debouncer/createDebouncedSignal.d.cts +0 -79
  78. package/dist/debouncer/createDebouncedSignal.js.map +0 -1
  79. package/dist/debouncer/createDebouncedValue.cjs +0 -77
  80. package/dist/debouncer/createDebouncedValue.cjs.map +0 -1
  81. package/dist/debouncer/createDebouncedValue.d.cts +0 -70
  82. package/dist/debouncer/createDebouncedValue.js.map +0 -1
  83. package/dist/debouncer/createDebouncer.cjs +0 -129
  84. package/dist/debouncer/createDebouncer.cjs.map +0 -1
  85. package/dist/debouncer/createDebouncer.d.cts +0 -144
  86. package/dist/debouncer/createDebouncer.js.map +0 -1
  87. package/dist/debouncer/index.cjs +0 -15
  88. package/dist/debouncer/index.d.cts +0 -5
  89. package/dist/index.cjs +0 -47
  90. package/dist/index.d.cts +0 -20
  91. package/dist/provider/PacerProvider.cjs +0 -27
  92. package/dist/provider/PacerProvider.cjs.map +0 -1
  93. package/dist/provider/PacerProvider.d.cts +0 -28
  94. package/dist/provider/PacerProvider.js.map +0 -1
  95. package/dist/provider/index.cjs +0 -6
  96. package/dist/provider/index.d.cts +0 -2
  97. package/dist/queuer/createQueuedSignal.cjs +0 -129
  98. package/dist/queuer/createQueuedSignal.cjs.map +0 -1
  99. package/dist/queuer/createQueuedSignal.d.cts +0 -121
  100. package/dist/queuer/createQueuedSignal.js.map +0 -1
  101. package/dist/queuer/createQueuer.cjs +0 -133
  102. package/dist/queuer/createQueuer.cjs.map +0 -1
  103. package/dist/queuer/createQueuer.d.cts +0 -147
  104. package/dist/queuer/createQueuer.js.map +0 -1
  105. package/dist/queuer/index.cjs +0 -13
  106. package/dist/queuer/index.d.cts +0 -4
  107. package/dist/rate-limiter/createRateLimitedSignal.cjs +0 -102
  108. package/dist/rate-limiter/createRateLimitedSignal.cjs.map +0 -1
  109. package/dist/rate-limiter/createRateLimitedSignal.d.cts +0 -93
  110. package/dist/rate-limiter/createRateLimitedSignal.js.map +0 -1
  111. package/dist/rate-limiter/createRateLimitedValue.cjs +0 -102
  112. package/dist/rate-limiter/createRateLimitedValue.cjs.map +0 -1
  113. package/dist/rate-limiter/createRateLimitedValue.d.cts +0 -95
  114. package/dist/rate-limiter/createRateLimitedValue.js.map +0 -1
  115. package/dist/rate-limiter/createRateLimiter.cjs +0 -157
  116. package/dist/rate-limiter/createRateLimiter.cjs.map +0 -1
  117. package/dist/rate-limiter/createRateLimiter.d.cts +0 -173
  118. package/dist/rate-limiter/createRateLimiter.js.map +0 -1
  119. package/dist/rate-limiter/index.cjs +0 -15
  120. package/dist/rate-limiter/index.d.cts +0 -5
  121. package/dist/throttler/createThrottledSignal.cjs +0 -79
  122. package/dist/throttler/createThrottledSignal.cjs.map +0 -1
  123. package/dist/throttler/createThrottledSignal.d.cts +0 -70
  124. package/dist/throttler/createThrottledSignal.js.map +0 -1
  125. package/dist/throttler/createThrottledValue.cjs +0 -74
  126. package/dist/throttler/createThrottledValue.cjs.map +0 -1
  127. package/dist/throttler/createThrottledValue.d.cts +0 -67
  128. package/dist/throttler/createThrottledValue.js.map +0 -1
  129. package/dist/throttler/createThrottler.cjs +0 -132
  130. package/dist/throttler/createThrottler.cjs.map +0 -1
  131. package/dist/throttler/createThrottler.d.cts +0 -147
  132. package/dist/throttler/createThrottler.js.map +0 -1
  133. package/dist/throttler/index.cjs +0 -15
  134. package/dist/throttler/index.d.cts +0 -5
  135. package/dist/types/index.cjs +0 -8
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -8
  138. package/dist/utils/index.d.cts +0 -1
  139. package/src/async-batcher/createAsyncBatcher.ts +0 -234
  140. package/src/async-batcher/index.ts +0 -3
  141. package/src/async-debouncer/createAsyncDebouncer.ts +0 -225
  142. package/src/async-debouncer/index.ts +0 -4
  143. package/src/async-queuer/createAsyncQueuer.ts +0 -226
  144. package/src/async-queuer/index.ts +0 -3
  145. package/src/async-rate-limiter/createAsyncRateLimiter.ts +0 -269
  146. package/src/async-rate-limiter/index.ts +0 -4
  147. package/src/async-throttler/createAsyncThrottler.ts +0 -225
  148. package/src/async-throttler/index.ts +0 -4
  149. package/src/batcher/createBatcher.ts +0 -199
  150. package/src/batcher/index.ts +0 -3
  151. package/src/debouncer/createDebouncedSignal.ts +0 -92
  152. package/src/debouncer/createDebouncedValue.ts +0 -85
  153. package/src/debouncer/createDebouncer.ts +0 -201
  154. package/src/debouncer/index.ts +0 -6
  155. package/src/index.ts +0 -46
  156. package/src/provider/PacerProvider.tsx +0 -63
  157. package/src/provider/index.ts +0 -1
  158. package/src/queuer/createQueuedSignal.ts +0 -138
  159. package/src/queuer/createQueuer.ts +0 -199
  160. package/src/queuer/index.ts +0 -4
  161. package/src/rate-limiter/createRateLimitedSignal.ts +0 -117
  162. package/src/rate-limiter/createRateLimitedValue.ts +0 -110
  163. package/src/rate-limiter/createRateLimiter.ts +0 -226
  164. package/src/rate-limiter/index.ts +0 -5
  165. package/src/throttler/createThrottledSignal.ts +0 -81
  166. package/src/throttler/createThrottledValue.ts +0 -82
  167. package/src/throttler/createThrottler.ts +0 -204
  168. package/src/throttler/index.ts +0 -6
  169. package/src/types/index.ts +0 -1
  170. package/src/utils/index.ts +0 -1
@@ -1,163 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AnyAsyncFunction } from "@tanstack/pacer/types";
4
- import { AsyncThrottler, AsyncThrottlerOptions, AsyncThrottlerState } from "@tanstack/pacer/async-throttler";
5
- //#region src/async-throttler/createAsyncThrottler.d.ts
6
- interface SolidAsyncThrottlerOptions<TFn extends AnyAsyncFunction, TSelected = {}> extends AsyncThrottlerOptions<TFn> {
7
- /**
8
- * Optional callback invoked when the owning component unmounts. Receives the throttler instance.
9
- * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.
10
- */
11
- onUnmount?: (throttler: SolidAsyncThrottler<TFn, TSelected>) => void;
12
- }
13
- interface SolidAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncThrottler<TFn>, 'store'> {
14
- /**
15
- * A Solid component that allows you to subscribe to the throttler state.
16
- *
17
- * This is useful for tracking specific parts of the throttler state
18
- * deep in your component tree without needing to pass a selector to the hook.
19
- *
20
- * @example
21
- * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
22
- * {(state) => (
23
- * <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
24
- * )}
25
- * </throttler.Subscribe>
26
- */
27
- Subscribe: <TSelected>(props: {
28
- selector: (state: AsyncThrottlerState<TFn>) => TSelected;
29
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
30
- }) => JSX.Element;
31
- /**
32
- * Reactive state that will be updated when the throttler state changes
33
- *
34
- * Use this instead of `throttler.store.state`
35
- */
36
- readonly state: Accessor<Readonly<TSelected>>;
37
- /**
38
- * @deprecated Use `throttler.state` instead of `throttler.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 `useSelector` hook internally.
40
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
41
- */
42
- readonly store: Store<Readonly<AsyncThrottlerState<TFn>>>;
43
- }
44
- /**
45
- * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async function can execute.
46
- *
47
- * This hook is designed to be flexible and state-management agnostic - it simply returns a throttler instance that
48
- * you can integrate with any state management solution (createSignal, etc).
49
- *
50
- * Async throttling ensures an async function executes at most once within a specified time window,
51
- * regardless of how many times it is called. This is useful for rate-limiting expensive API calls,
52
- * database operations, or other async tasks.
53
- *
54
- * Unlike the non-async Throttler, this async version supports returning values from the throttled function,
55
- * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call
56
- * instead of setting the result on a state variable from within the throttled function.
57
- *
58
- * Error Handling:
59
- * - If an `onError` handler is provided, it will be called with the error and throttler instance
60
- * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown
61
- * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed
62
- * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown
63
- * - The error state can be checked using the underlying AsyncThrottler instance
64
- *
65
- * ## State Management and Selector
66
- *
67
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
68
- * in two ways:
69
- *
70
- * **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
71
- *
72
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
73
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
74
- * in child components.
75
- *
76
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
77
- *
78
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
79
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
80
- * state changes occur.
81
- *
82
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
83
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
84
- * updates and gives you full control over when your component tracks state changes.
85
- *
86
- * Available state properties:
87
- * - `canLeadingExecute`: Whether the throttler can execute on the leading edge
88
- * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge
89
- * - `executionCount`: Number of function executions that have been completed
90
- * - `hasError`: Whether the last execution resulted in an error
91
- * - `isPending`: Whether the throttler is waiting for the timeout to trigger execution
92
- * - `isExecuting`: Whether an async function execution is currently in progress
93
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
94
- * - `lastError`: The error from the most recent failed execution (if any)
95
- * - `lastExecutionTime`: Timestamp of the last execution
96
- * - `lastResult`: The result from the most recent successful execution
97
- * - `nextExecutionTime`: Timestamp of the next allowed execution
98
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')
99
- *
100
- * ## Unmount behavior
101
- *
102
- * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.
103
- * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.
104
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
105
- *
106
- * ```tsx
107
- * const throttler = createAsyncThrottler(fn, {
108
- * wait: 1000,
109
- * onUnmount: (t) => t.flush()
110
- * });
111
- * ```
112
- *
113
- * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.
114
- * If your throttled function updates Solid signals, those updates may run after the component has
115
- * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when
116
- * using onUnmount with flush.
117
- *
118
- * @example
119
- * ```tsx
120
- * // Default behavior - no reactive state subscriptions
121
- * const { maybeExecute } = createAsyncThrottler(
122
- * async (id: string) => {
123
- * const data = await api.fetchData(id);
124
- * return data;
125
- * },
126
- * { wait: 1000 }
127
- * );
128
- *
129
- * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
130
- * const throttler = createAsyncThrottler(
131
- * async (query) => {
132
- * const result = await searchAPI(query);
133
- * return result;
134
- * },
135
- * { wait: 2000 },
136
- * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
137
- * );
138
- *
139
- * // Opt-in to track error state changes (optimized for error handling)
140
- * const throttler = createAsyncThrottler(
141
- * async (query) => {
142
- * const result = await searchAPI(query);
143
- * return result;
144
- * },
145
- * {
146
- * wait: 2000,
147
- * leading: true, // Execute immediately on first call
148
- * trailing: false, // Skip trailing edge updates
149
- * onError: (error) => {
150
- * console.error('API call failed:', error);
151
- * }
152
- * },
153
- * (state) => ({ hasError: state.hasError, lastError: state.lastError })
154
- * );
155
- *
156
- * // Access the selected state (will be empty object {} unless selector provided)
157
- * const { isPending, isExecuting } = throttler.state();
158
- * ```
159
- */
160
- declare function createAsyncThrottler<TFn extends AnyAsyncFunction, TSelected = {}>(fn: TFn, options: SolidAsyncThrottlerOptions<TFn, TSelected>, selector?: (state: AsyncThrottlerState<TFn>) => TSelected): SolidAsyncThrottler<TFn, TSelected>;
161
- //#endregion
162
- export { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler };
163
- //# sourceMappingURL=createAsyncThrottler.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createAsyncThrottler.js","names":[],"sources":["../../src/async-throttler/createAsyncThrottler.ts"],"sourcesContent":["import { createEffect, onCleanup } from 'solid-js'\nimport { AsyncThrottler } from '@tanstack/pacer/async-throttler'\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 { AnyAsyncFunction } from '@tanstack/pacer/types'\nimport type {\n AsyncThrottlerOptions,\n AsyncThrottlerState,\n} from '@tanstack/pacer/async-throttler'\n\nexport interface SolidAsyncThrottlerOptions<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends AsyncThrottlerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the throttler instance.\n * When provided, replaces the default cleanup (cancel + abort); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (throttler: SolidAsyncThrottler<TFn, TSelected>) => void\n}\n\nexport interface SolidAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncThrottler<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, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Pending...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </throttler.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncThrottlerState<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<AsyncThrottlerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncThrottler` instance to limit how often an async 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, etc).\n *\n * Async throttling ensures an async 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 expensive API calls,\n * database operations, or other async tasks.\n *\n * Unlike the non-async Throttler, this async version supports returning values from the throttled 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 throttled function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and throttler 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 AsyncThrottler 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 `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 * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the throttler 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 * - `lastExecutionTime`: Timestamp of the last execution\n * - `lastResult`: The result from the most recent successful execution\n * - `nextExecutionTime`: Timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution and aborts any in-flight execution when the owning component unmounts.\n * Abort only cancels underlying operations (e.g. fetch) when the abort signal from `getAbortSignal()` is passed to them.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const throttler = createAsyncThrottler(fn, {\n * wait: 1000,\n * onUnmount: (t) => t.flush()\n * });\n * ```\n *\n * Note: For async utils, `flush()` returns a Promise and runs fire-and-forget in the cleanup.\n * If your throttled function updates Solid signals, those updates may run after the component has\n * unmounted, which can cause unexpected reactive updates. Guard your callbacks accordingly when\n * using onUnmount with flush.\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncThrottler(\n * async (id: string) => {\n * const data = await api.fetchData(id);\n * return data;\n * },\n * { wait: 1000 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * { wait: 2000 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const throttler = createAsyncThrottler(\n * async (query) => {\n * const result = await searchAPI(query);\n * return result;\n * },\n * {\n * wait: 2000,\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 } = throttler.state();\n * ```\n */\nexport function createAsyncThrottler<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: SolidAsyncThrottlerOptions<TFn, TSelected>,\n selector: (state: AsyncThrottlerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncThrottler<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncThrottler,\n ...options,\n } as SolidAsyncThrottlerOptions<TFn, TSelected>\n const asyncThrottler = new AsyncThrottler(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncThrottler<TFn, TSelected>\n\n asyncThrottler.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncThrottlerState<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 asyncThrottler.abort()\n }\n })\n })\n\n return {\n ...asyncThrottler,\n state,\n } as SolidAsyncThrottler<TFn, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA8KA,SAAgB,qBAId,IACA,SACA,kBACG,CAAC,IACiC;CACrC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,iBAAiB,IAAI,eACzB,IACA,aACF;CAEA,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,QACX,CAAC;CAED,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,cAAc;QACjC;IACL,eAAe,OAAO;IACtB,eAAe,MAAM;GACvB;EACF,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createAsyncThrottler = require('./createAsyncThrottler.cjs');
3
-
4
- exports.createAsyncThrottler = require_createAsyncThrottler.createAsyncThrottler;
5
- var _tanstack_pacer_async_throttler = require("@tanstack/pacer/async-throttler");
6
- Object.keys(_tanstack_pacer_async_throttler).forEach(function (k) {
7
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
- enumerable: true,
9
- get: function () { return _tanstack_pacer_async_throttler[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler } from "./createAsyncThrottler.cjs";
2
- export * from "@tanstack/pacer/async-throttler";
3
- export { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler };
@@ -1,132 +0,0 @@
1
- const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let solid_js = require("solid-js");
3
- let _tanstack_solid_store = require("@tanstack/solid-store");
4
- let _tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
5
-
6
- //#region src/batcher/createBatcher.ts
7
- /**
8
- * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
9
- *
10
- * Features:
11
- * - Batch processing of items using the provided `fn` function
12
- * - Configurable batch size and wait time
13
- * - Custom batch processing logic via getShouldExecute
14
- * - Event callbacks for monitoring batch operations
15
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
16
- *
17
- * The batcher collects items and processes them in batches based on:
18
- * - Maximum batch size
19
- * - Time-based batching (process after X milliseconds)
20
- * - Custom batch processing logic via getShouldExecute
21
- *
22
- * ## State Management and Selector
23
- *
24
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
25
- * in two ways:
26
- *
27
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
28
- *
29
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
30
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
31
- * in child components.
32
- *
33
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
34
- *
35
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
36
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
37
- * state changes occur.
38
- *
39
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
40
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
41
- * updates and gives you full control over when your component tracks state changes.
42
- *
43
- * Available state properties:
44
- * - `executionCount`: Number of batch executions that have been completed
45
- * - `isRunning`: Whether the batcher is currently running (not stopped)
46
- * - `items`: Array of items currently queued for batching
47
- * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
48
- *
49
- * ## Unmount behavior
50
- *
51
- * By default, the primitive cancels any pending batch when the owning component unmounts.
52
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
53
- *
54
- * ```tsx
55
- * const batcher = createBatcher(fn, {
56
- * maxSize: 10,
57
- * wait: 2000,
58
- * onUnmount: (b) => b.flush()
59
- * });
60
- * ```
61
- *
62
- * Example usage:
63
- * ```tsx
64
- * // Default behavior - no reactive state subscriptions
65
- * const batcher = createBatcher(
66
- * (items) => {
67
- * // Process batch of items
68
- * console.log('Processing batch:', items);
69
- * },
70
- * {
71
- * maxSize: 5,
72
- * wait: 2000,
73
- * onExecute: (batcher) => console.log('Batch executed'),
74
- * getShouldExecute: (items) => items.length >= 3
75
- * }
76
- * );
77
- *
78
- * // Opt-in to track items or isRunning changes (optimized for UI updates)
79
- * const batcher = createBatcher(
80
- * (items) => console.log('Processing batch:', items),
81
- * { maxSize: 5, wait: 2000 },
82
- * (state) => ({ items: state.items, isRunning: state.isRunning })
83
- * );
84
- *
85
- * // Opt-in to track execution metrics changes (optimized for tracking progress)
86
- * const batcher = createBatcher(
87
- * (items) => console.log('Processing batch:', items),
88
- * { maxSize: 5, wait: 2000 },
89
- * (state) => ({
90
- * executionCount: state.executionCount,
91
- * totalItemsProcessed: state.totalItemsProcessed
92
- * })
93
- * );
94
- *
95
- * // Add items to batch
96
- * batcher.addItem('task1');
97
- * batcher.addItem('task2');
98
- *
99
- * // Control the batcher
100
- * batcher.stop(); // Pause processing
101
- * batcher.start(); // Resume processing
102
- *
103
- * // Access the selected state (will be empty object {} unless selector provided)
104
- * const { items, isRunning } = batcher.state();
105
- * ```
106
- */
107
- function createBatcher(fn, options = {}, selector = () => ({})) {
108
- const mergedOptions = {
109
- ...require_PacerProvider.useDefaultPacerOptions().batcher,
110
- ...options
111
- };
112
- const batcher = new _tanstack_pacer_batcher.Batcher(fn, mergedOptions);
113
- batcher.Subscribe = function Subscribe(props) {
114
- const selected = (0, _tanstack_solid_store.useSelector)(batcher.store, props.selector, { compare: _tanstack_solid_store.shallow });
115
- return typeof props.children === "function" ? props.children(selected) : props.children;
116
- };
117
- const state = (0, _tanstack_solid_store.useSelector)(batcher.store, selector, { compare: _tanstack_solid_store.shallow });
118
- (0, solid_js.createEffect)(() => {
119
- (0, solid_js.onCleanup)(() => {
120
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(batcher);
121
- else batcher.cancel();
122
- });
123
- });
124
- return {
125
- ...batcher,
126
- state
127
- };
128
- }
129
-
130
- //#endregion
131
- exports.createBatcher = createBatcher;
132
- //# sourceMappingURL=createBatcher.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBatcher.cjs","names":["useDefaultPacerOptions","Batcher","useSelector","shallow"],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\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 { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const batcher = createBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: SolidBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as SolidBatcherOptions<TValue, TSelected>\n const batcher = new Batcher(fn, mergedOptions) as unknown as SolidBatcher<\n TValue,\n TSelected\n >\n\n batcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(batcher.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(batcher.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(batcher)\n } else {\n batcher.cancel()\n }\n })\n })\n\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,cACd,IACA,UAAkD,CAAC,GACnD,kBACG,CAAC,IAC6B;CACjC,MAAM,gBAAgB;EACpB,GAAGA,6CAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,UAAU,IAAIC,gCAAQ,IAAI,aAAa;CAK7C,QAAQ,YAAY,SAAS,UAAqB,OAG/C;EACD,MAAM,eAAWC,mCAAY,QAAQ,OAAO,MAAM,UAAU,EAC1D,SAASC,8BACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,YAAQD,mCAAY,QAAQ,OAAO,UAAU,EAAE,SAASC,8BAAQ,CAAC;CAEvE,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;QAE/B,QAAQ,OAAO;EAEnB,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,146 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { Batcher, BatcherOptions, BatcherState } from "@tanstack/pacer/batcher";
4
- //#region src/batcher/createBatcher.d.ts
5
- interface SolidBatcherOptions<TValue, TSelected = {}> extends BatcherOptions<TValue> {
6
- /**
7
- * Optional callback invoked when the owning component unmounts. Receives the batcher instance.
8
- * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
9
- */
10
- onUnmount?: (batcher: SolidBatcher<TValue, TSelected>) => void;
11
- }
12
- interface SolidBatcher<TValue, TSelected = {}> extends Omit<Batcher<TValue>, 'store'> {
13
- /**
14
- * A Solid component that allows you to subscribe to the batcher state.
15
- *
16
- * This is useful for tracking specific parts of the batcher state
17
- * deep in your component tree without needing to pass a selector to the hook.
18
- *
19
- * @example
20
- * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>
21
- * {(state) => (
22
- * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>
23
- * )}
24
- * </batcher.Subscribe>
25
- */
26
- Subscribe: <TSelected>(props: {
27
- selector: (state: BatcherState<TValue>) => TSelected;
28
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
29
- }) => JSX.Element;
30
- /**
31
- * Reactive state that will be updated when the batcher state changes
32
- *
33
- * Use this instead of `batcher.store.state`
34
- */
35
- readonly state: Accessor<Readonly<TSelected>>;
36
- /**
37
- * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.
38
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
39
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
40
- */
41
- readonly store: Store<Readonly<BatcherState<TValue>>>;
42
- }
43
- /**
44
- * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.
45
- *
46
- * Features:
47
- * - Batch processing of items using the provided `fn` function
48
- * - Configurable batch size and wait time
49
- * - Custom batch processing logic via getShouldExecute
50
- * - Event callbacks for monitoring batch operations
51
- * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity
52
- *
53
- * The batcher collects items and processes them in batches based on:
54
- * - Maximum batch size
55
- * - Time-based batching (process after X milliseconds)
56
- * - Custom batch processing logic via getShouldExecute
57
- *
58
- * ## State Management and Selector
59
- *
60
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
61
- * in two ways:
62
- *
63
- * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
64
- *
65
- * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
66
- * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
67
- * in child components.
68
- *
69
- * **2. Using the `selector` parameter (For hook-level subscriptions)**
70
- *
71
- * The `selector` parameter allows you to specify which state changes will trigger reactive updates
72
- * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
73
- * state changes occur.
74
- *
75
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
76
- * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
77
- * updates and gives you full control over when your component tracks state changes.
78
- *
79
- * Available state properties:
80
- * - `executionCount`: Number of batch executions that have been completed
81
- * - `isRunning`: Whether the batcher is currently running (not stopped)
82
- * - `items`: Array of items currently queued for batching
83
- * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches
84
- *
85
- * ## Unmount behavior
86
- *
87
- * By default, the primitive cancels any pending batch when the owning component unmounts.
88
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
89
- *
90
- * ```tsx
91
- * const batcher = createBatcher(fn, {
92
- * maxSize: 10,
93
- * wait: 2000,
94
- * onUnmount: (b) => b.flush()
95
- * });
96
- * ```
97
- *
98
- * Example usage:
99
- * ```tsx
100
- * // Default behavior - no reactive state subscriptions
101
- * const batcher = createBatcher(
102
- * (items) => {
103
- * // Process batch of items
104
- * console.log('Processing batch:', items);
105
- * },
106
- * {
107
- * maxSize: 5,
108
- * wait: 2000,
109
- * onExecute: (batcher) => console.log('Batch executed'),
110
- * getShouldExecute: (items) => items.length >= 3
111
- * }
112
- * );
113
- *
114
- * // Opt-in to track items or isRunning changes (optimized for UI updates)
115
- * const batcher = createBatcher(
116
- * (items) => console.log('Processing batch:', items),
117
- * { maxSize: 5, wait: 2000 },
118
- * (state) => ({ items: state.items, isRunning: state.isRunning })
119
- * );
120
- *
121
- * // Opt-in to track execution metrics changes (optimized for tracking progress)
122
- * const batcher = createBatcher(
123
- * (items) => console.log('Processing batch:', items),
124
- * { maxSize: 5, wait: 2000 },
125
- * (state) => ({
126
- * executionCount: state.executionCount,
127
- * totalItemsProcessed: state.totalItemsProcessed
128
- * })
129
- * );
130
- *
131
- * // Add items to batch
132
- * batcher.addItem('task1');
133
- * batcher.addItem('task2');
134
- *
135
- * // Control the batcher
136
- * batcher.stop(); // Pause processing
137
- * batcher.start(); // Resume processing
138
- *
139
- * // Access the selected state (will be empty object {} unless selector provided)
140
- * const { items, isRunning } = batcher.state();
141
- * ```
142
- */
143
- declare function createBatcher<TValue, TSelected = {}>(fn: (items: Array<TValue>) => void, options?: SolidBatcherOptions<TValue, TSelected>, selector?: (state: BatcherState<TValue>) => TSelected): SolidBatcher<TValue, TSelected>;
144
- //#endregion
145
- export { SolidBatcher, SolidBatcherOptions, createBatcher };
146
- //# sourceMappingURL=createBatcher.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createBatcher.js","names":[],"sources":["../../src/batcher/createBatcher.ts"],"sourcesContent":["import { Batcher } from '@tanstack/pacer/batcher'\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 { BatcherOptions, BatcherState } from '@tanstack/pacer/batcher'\n\nexport interface SolidBatcherOptions<\n TValue,\n TSelected = {},\n> extends BatcherOptions<TValue> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the batcher instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (batcher: SolidBatcher<TValue, TSelected>) => void\n}\n\nexport interface SolidBatcher<TValue, TSelected = {}> extends Omit<\n Batcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<BatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Batcher instance for managing batches of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Batch processing of items using the provided `fn` function\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of batch executions that have been completed\n * - `isRunning`: Whether the batcher is currently running (not stopped)\n * - `items`: Array of items currently queued for batching\n * - `totalItemsProcessed`: Total number of individual items that have been processed across all batches\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending batch when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const batcher = createBatcher(fn, {\n * maxSize: 10,\n * wait: 2000,\n * onUnmount: (b) => b.flush()\n * });\n * ```\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const batcher = createBatcher(\n * (items) => {\n * // Process batch of items\n * console.log('Processing batch:', items);\n * },\n * {\n * maxSize: 5,\n * wait: 2000,\n * onExecute: (batcher) => console.log('Batch executed'),\n * getShouldExecute: (items) => items.length >= 3\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const batcher = createBatcher(\n * (items) => console.log('Processing batch:', items),\n * { maxSize: 5, wait: 2000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * totalItemsProcessed: state.totalItemsProcessed\n * })\n * );\n *\n * // Add items to batch\n * batcher.addItem('task1');\n * batcher.addItem('task2');\n *\n * // Control the batcher\n * batcher.stop(); // Pause processing\n * batcher.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = batcher.state();\n * ```\n */\nexport function createBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => void,\n options: SolidBatcherOptions<TValue, TSelected> = {},\n selector: (state: BatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().batcher,\n ...options,\n } as SolidBatcherOptions<TValue, TSelected>\n const batcher = new Batcher(fn, mergedOptions) as unknown as SolidBatcher<\n TValue,\n TSelected\n >\n\n batcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: BatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(batcher.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(batcher.store, selector, { compare: shallow })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(batcher)\n } else {\n batcher.cancel()\n }\n })\n })\n\n return {\n ...batcher,\n state,\n } as SolidBatcher<TValue, TSelected>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0JA,SAAgB,cACd,IACA,UAAkD,CAAC,GACnD,kBACG,CAAC,IAC6B;CACjC,MAAM,gBAAgB;EACpB,GAAG,uBAAuB,CAAC,CAAC;EAC5B,GAAG;CACL;CACA,MAAM,UAAU,IAAI,QAAQ,IAAI,aAAa;CAK7C,QAAQ,YAAY,SAAS,UAAqB,OAG/C;EACD,MAAM,WAAW,YAAY,QAAQ,OAAO,MAAM,UAAU,EAC1D,SAAS,QACX,CAAC;EAED,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,QAAQ,IACvB,MAAM;CACZ;CAEA,MAAM,QAAQ,YAAY,QAAQ,OAAO,UAAU,EAAE,SAAS,QAAQ,CAAC;CAEvE,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,OAAO;QAE/B,QAAQ,OAAO;EAEnB,CAAC;CACH,CAAC;CAED,OAAO;EACL,GAAG;EACH;CACF;AACF"}
@@ -1,11 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createBatcher = require('./createBatcher.cjs');
3
-
4
- exports.createBatcher = require_createBatcher.createBatcher;
5
- var _tanstack_pacer_batcher = require("@tanstack/pacer/batcher");
6
- Object.keys(_tanstack_pacer_batcher).forEach(function (k) {
7
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
8
- enumerable: true,
9
- get: function () { return _tanstack_pacer_batcher[k]; }
10
- });
11
- });
@@ -1,3 +0,0 @@
1
- import { SolidBatcher, SolidBatcherOptions, createBatcher } from "./createBatcher.cjs";
2
- export * from "@tanstack/pacer/batcher";
3
- export { SolidBatcher, SolidBatcherOptions, createBatcher };
@@ -1,88 +0,0 @@
1
- const require_createDebouncer = require('./createDebouncer.cjs');
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/debouncer/createDebouncedSignal.ts
5
- /**
6
- * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.
7
- * This hook provides both the current debounced value and methods to update it.
8
- *
9
- * The state value is only updated after the specified wait time has elapsed since the last update attempt.
10
- * If another update is attempted before the wait time expires, the timer resets and starts waiting again.
11
- * This is useful for handling frequent state updates that should be throttled, like search input values
12
- * or window resize dimensions.
13
- *
14
- * The hook returns a tuple containing:
15
- * - The current debounced value accessor
16
- * - A function to update the debounced value
17
- * - The debouncer instance with additional control methods and state signals
18
- *
19
- * ## State Management and Selector
20
- *
21
- * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.
22
- * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,
23
- * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.
24
- *
25
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
26
- * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you
27
- * full control over when your component subscribes to state changes. Only when you provide a selector will
28
- * the reactive system track the selected state values.
29
- *
30
- * Available debouncer state properties:
31
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
32
- * - `executionCount`: Number of function executions that have been completed
33
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
34
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
35
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
36
- *
37
- * @example
38
- * ```tsx
39
- * // Default behavior - no reactive state subscriptions
40
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
41
- * wait: 500 // Wait 500ms after last keystroke
42
- * });
43
- *
44
- * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)
45
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
46
- * '',
47
- * { wait: 500 },
48
- * (state) => ({ isPending: state.isPending })
49
- * );
50
- *
51
- * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)
52
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(
53
- * '',
54
- * { wait: 500 },
55
- * (state) => ({ executionCount: state.executionCount })
56
- * );
57
- *
58
- * // Update value - will be debounced
59
- * const handleChange = (e) => {
60
- * setSearchTerm(e.target.value);
61
- * };
62
- *
63
- * // Access debouncer state via signals
64
- * console.log('Executions:', debouncer.state().executionCount);
65
- * console.log('Is pending:', debouncer.state().isPending);
66
- *
67
- * // In onExecute callback, use get* methods
68
- * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {
69
- * wait: 500,
70
- * onExecute: (debouncer) => {
71
- * console.log('Total executions:', debouncer.getExecutionCount());
72
- * }
73
- * });
74
- * ```
75
- */
76
- function createDebouncedSignal(value, initialOptions, selector) {
77
- const [debouncedValue, setDebouncedValue] = (0, solid_js.createSignal)(value);
78
- const debouncer = require_createDebouncer.createDebouncer(setDebouncedValue, initialOptions, selector);
79
- return [
80
- debouncedValue,
81
- debouncer.maybeExecute,
82
- debouncer
83
- ];
84
- }
85
-
86
- //#endregion
87
- exports.createDebouncedSignal = createDebouncedSignal;
88
- //# sourceMappingURL=createDebouncedSignal.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncedSignal.cjs","names":["createSignal","createDebouncer"],"sources":["../../src/debouncer/createDebouncedSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createDebouncer } from './createDebouncer'\nimport type { SolidDebouncer, SolidDebouncerOptions } from './createDebouncer'\nimport type { Accessor, Setter } from 'solid-js'\nimport type { DebouncerState } from '@tanstack/pacer/debouncer'\n\n/**\n * A Solid hook that creates a debounced state value, combining Solid's createSignal with debouncing functionality.\n * This hook provides both the current debounced value and methods to update it.\n *\n * The state value is only updated after the specified wait time has elapsed since the last update attempt.\n * If another update is attempted before the wait time expires, the timer resets and starts waiting again.\n * This is useful for handling frequent state updates that should be throttled, like search input values\n * or window resize dimensions.\n *\n * The hook returns a tuple containing:\n * - The current debounced value accessor\n * - A function to update the debounced value\n * - The debouncer instance with additional control methods and state signals\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying debouncer instance.\n * The `selector` parameter allows you to specify which debouncer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary subscriptions when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary reactive updates and gives you\n * full control over when your component subscribes to state changes. Only when you provide a selector will\n * the reactive system track the selected state values.\n *\n * Available debouncer state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500 // Wait 500ms after last keystroke\n * });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to reactive updates when execution count changes (optimized for tracking executions)\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal(\n * '',\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Update value - will be debounced\n * const handleChange = (e) => {\n * setSearchTerm(e.target.value);\n * };\n *\n * // Access debouncer state via signals\n * console.log('Executions:', debouncer.state().executionCount);\n * console.log('Is pending:', debouncer.state().isPending);\n *\n * // In onExecute callback, use get* methods\n * const [searchTerm, setSearchTerm, debouncer] = createDebouncedSignal('', {\n * wait: 500,\n * onExecute: (debouncer) => {\n * console.log('Total executions:', debouncer.getExecutionCount());\n * }\n * });\n * ```\n */\nexport function createDebouncedSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: SolidDebouncerOptions<Setter<TValue>, TSelected>,\n selector?: (state: DebouncerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidDebouncer<Setter<TValue>, TSelected>,\n] {\n const [debouncedValue, setDebouncedValue] = createSignal<TValue>(value)\n\n const debouncer = createDebouncer(setDebouncedValue, initialOptions, selector)\n\n return [debouncedValue, debouncer.maybeExecute as Setter<TValue>, debouncer]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6EA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,yBAAqBA,uBAAqB,KAAK;CAEtE,MAAM,YAAYC,wCAAgB,mBAAmB,gBAAgB,QAAQ;CAE7E,OAAO;EAAC;EAAgB,UAAU;EAAgC;CAAS;AAC7E"}