@tanstack/solid-pacer 0.21.1 → 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 +21 -6
  2. package/dist/async-batcher/createAsyncBatcher.d.ts +5 -10
  3. package/dist/async-batcher/createAsyncBatcher.js +2 -5
  4. package/dist/async-debouncer/createAsyncDebouncer.d.ts +8 -12
  5. package/dist/async-debouncer/createAsyncDebouncer.js +5 -7
  6. package/dist/async-queuer/createAsyncQueuer.d.ts +9 -12
  7. package/dist/async-queuer/createAsyncQueuer.js +4 -5
  8. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +10 -13
  9. package/dist/async-rate-limiter/createAsyncRateLimiter.js +7 -8
  10. package/dist/async-throttler/createAsyncThrottler.d.ts +8 -14
  11. package/dist/async-throttler/createAsyncThrottler.js +5 -9
  12. package/dist/batcher/createBatcher.d.ts +11 -15
  13. package/dist/batcher/createBatcher.js +6 -8
  14. package/dist/debouncer/createDebouncedSignal.d.ts +2 -5
  15. package/dist/debouncer/createDebouncedSignal.js +1 -2
  16. package/dist/debouncer/createDebouncedValue.d.ts +2 -5
  17. package/dist/debouncer/createDebouncedValue.js +1 -2
  18. package/dist/debouncer/createDebouncer.d.ts +4 -7
  19. package/dist/debouncer/createDebouncer.js +1 -2
  20. package/dist/provider/PacerProvider.d.ts +6 -9
  21. package/dist/provider/PacerProvider.js +1 -2
  22. package/dist/queuer/createQueuedSignal.d.ts +2 -5
  23. package/dist/queuer/createQueuedSignal.js +1 -2
  24. package/dist/queuer/createQueuer.d.ts +4 -7
  25. package/dist/queuer/createQueuer.js +1 -2
  26. package/dist/rate-limiter/createRateLimitedSignal.d.ts +12 -14
  27. package/dist/rate-limiter/createRateLimitedSignal.js +11 -11
  28. package/dist/rate-limiter/createRateLimitedValue.d.ts +2 -5
  29. package/dist/rate-limiter/createRateLimitedValue.js +1 -2
  30. package/dist/rate-limiter/createRateLimiter.d.ts +8 -10
  31. package/dist/rate-limiter/createRateLimiter.js +5 -5
  32. package/dist/throttler/createThrottledSignal.d.ts +2 -7
  33. package/dist/throttler/createThrottledSignal.js +1 -4
  34. package/dist/throttler/createThrottledValue.d.ts +2 -7
  35. package/dist/throttler/createThrottledValue.js +1 -4
  36. package/dist/throttler/createThrottler.d.ts +4 -9
  37. package/dist/throttler/createThrottler.js +1 -4
  38. package/package.json +24 -68
  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 -178
  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 -164
  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 -170
  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 -209
  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 -164
  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 -147
  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 -80
  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 -71
  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 -145
  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 -29
  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 -122
  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 -148
  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 -94
  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 -96
  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 -174
  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 -71
  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 -68
  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 -148
  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 -9
  136. package/dist/types/index.d.cts +0 -1
  137. package/dist/utils/index.cjs +0 -9
  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,129 +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_debouncer = require("@tanstack/pacer/debouncer");
5
-
6
- //#region src/debouncer/createDebouncer.ts
7
- /**
8
- * A Solid hook that creates and manages a Debouncer instance.
9
- *
10
- * This is a lower-level hook that provides direct access to the Debouncer's functionality without
11
- * any built-in state management. This allows you to integrate it with any state management solution
12
- * you prefer (createSignal, Redux, Zustand, etc.).
13
- *
14
- * This hook provides debouncing functionality to limit how often a function can be called,
15
- * waiting for a specified delay before executing the latest call. This is useful for handling
16
- * frequent events like window resizing, scroll events, or real-time search inputs.
17
- *
18
- * The debouncer will only execute the function after the specified wait time has elapsed
19
- * since the last call. If the function is called again before the wait time expires, the
20
- * timer resets and starts waiting again.
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 `debouncer.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
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
45
- * - `executionCount`: Number of function executions that have been completed
46
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
47
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
48
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
49
- *
50
- * ## Unmount behavior
51
- *
52
- * By default, the primitive cancels any pending execution when the owning component unmounts.
53
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
54
- *
55
- * ```tsx
56
- * const debouncer = createDebouncer(fn, {
57
- * wait: 500,
58
- * onUnmount: (d) => d.flush()
59
- * });
60
- * ```
61
- *
62
- * @example
63
- * ```tsx
64
- * // Default behavior - no reactive state subscriptions
65
- * const debouncer = createDebouncer(
66
- * (query: string) => fetchSearchResults(query),
67
- * { wait: 500 }
68
- * );
69
- *
70
- * // Opt-in to track isPending changes (optimized for loading states)
71
- * const debouncer = createDebouncer(
72
- * (query: string) => fetchSearchResults(query),
73
- * { wait: 500 },
74
- * (state) => ({ isPending: state.isPending })
75
- * );
76
- *
77
- * // Opt-in to track executionCount changes (optimized for tracking execution)
78
- * const debouncer = createDebouncer(
79
- * (query: string) => fetchSearchResults(query),
80
- * { wait: 500 },
81
- * (state) => ({ executionCount: state.executionCount })
82
- * );
83
- *
84
- * // Multiple state properties - track when any of these change
85
- * const debouncer = createDebouncer(
86
- * (query: string) => fetchSearchResults(query),
87
- * { wait: 500 },
88
- * (state) => ({
89
- * isPending: state.isPending,
90
- * executionCount: state.executionCount,
91
- * status: state.status
92
- * })
93
- * );
94
- *
95
- * // In an event handler
96
- * const handleChange = (e) => {
97
- * debouncer.maybeExecute(e.target.value);
98
- * };
99
- *
100
- * // Access the selected state (will be empty object {} unless selector provided)
101
- * const { isPending } = debouncer.state();
102
- * ```
103
- */
104
- function createDebouncer(fn, options, selector = () => ({})) {
105
- const mergedOptions = {
106
- ...require_PacerProvider.useDefaultPacerOptions().debouncer,
107
- ...options
108
- };
109
- const asyncDebouncer = new _tanstack_pacer_debouncer.Debouncer(fn, mergedOptions);
110
- asyncDebouncer.Subscribe = function Subscribe(props) {
111
- const selected = (0, _tanstack_solid_store.useSelector)(asyncDebouncer.store, props.selector, { compare: _tanstack_solid_store.shallow });
112
- return typeof props.children === "function" ? props.children(selected) : props.children;
113
- };
114
- const state = (0, _tanstack_solid_store.useSelector)(asyncDebouncer.store, selector, { compare: _tanstack_solid_store.shallow });
115
- (0, solid_js.createEffect)(() => {
116
- (0, solid_js.onCleanup)(() => {
117
- if (mergedOptions.onUnmount) mergedOptions.onUnmount(asyncDebouncer);
118
- else asyncDebouncer.cancel();
119
- });
120
- });
121
- return {
122
- ...asyncDebouncer,
123
- state
124
- };
125
- }
126
-
127
- //#endregion
128
- exports.createDebouncer = createDebouncer;
129
- //# sourceMappingURL=createDebouncer.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncer.cjs","names":["useDefaultPacerOptions","Debouncer","shallow"],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncDebouncer.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(asyncDebouncer.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAGA,8CAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAIC,oCACzB,IACA,cACD;CAED,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,kDAAuB,eAAe,OAAO,MAAM,UAAU,EACjE,SAASC,+BACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,+CAAoB,eAAe,OAAO,UAAU,EACxD,SAASA,+BACV,CAAC;CAEF,iCAAmB;EACjB,8BAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,eAAe;QAEvC,eAAe,QAAQ;IAEzB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,145 +0,0 @@
1
- import { Store } from "@tanstack/solid-store";
2
- import { Accessor, JSX } from "solid-js";
3
- import { AnyFunction } from "@tanstack/pacer/types";
4
- import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
5
-
6
- //#region src/debouncer/createDebouncer.d.ts
7
- interface SolidDebouncerOptions<TFn extends AnyFunction, TSelected = {}> extends DebouncerOptions<TFn> {
8
- /**
9
- * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.
10
- * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.
11
- */
12
- onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void;
13
- }
14
- interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<TFn>, 'store'> {
15
- /**
16
- * A Solid component that allows you to subscribe to the debouncer state.
17
- *
18
- * This is useful for tracking specific parts of the debouncer state
19
- * deep in your component tree without needing to pass a selector to the hook.
20
- *
21
- * @example
22
- * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>
23
- * {(state) => (
24
- * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>
25
- * )}
26
- * </debouncer.Subscribe>
27
- */
28
- Subscribe: <TSelected>(props: {
29
- selector: (state: DebouncerState<TFn>) => TSelected;
30
- children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
31
- }) => JSX.Element;
32
- /**
33
- * Reactive state that will be updated when the debouncer state changes
34
- *
35
- * Use this instead of `debouncer.store.state`
36
- */
37
- readonly state: Accessor<Readonly<TSelected>>;
38
- /**
39
- * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.
40
- * The state on the store object is not reactive, as it has not been wrapped in a `useSelector` hook internally.
41
- * Although, you can make the state reactive by using the `useSelector` in your own usage.
42
- */
43
- readonly store: Store<Readonly<DebouncerState<TFn>>>;
44
- }
45
- /**
46
- * A Solid hook that creates and manages a Debouncer instance.
47
- *
48
- * This is a lower-level hook that provides direct access to the Debouncer's functionality without
49
- * any built-in state management. This allows you to integrate it with any state management solution
50
- * you prefer (createSignal, Redux, Zustand, etc.).
51
- *
52
- * This hook provides debouncing functionality to limit how often a function can be called,
53
- * waiting for a specified delay before executing the latest call. This is useful for handling
54
- * frequent events like window resizing, scroll events, or real-time search inputs.
55
- *
56
- * The debouncer will only execute the function after the specified wait time has elapsed
57
- * since the last call. If the function is called again before the wait time expires, the
58
- * timer resets and starts waiting again.
59
- *
60
- * ## State Management and Selector
61
- *
62
- * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
63
- * in two ways:
64
- *
65
- * **1. Using `debouncer.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.
76
- *
77
- * **By default, there will be no reactive state subscriptions** and you must opt-in to state
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.
80
- *
81
- * Available state properties:
82
- * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
83
- * - `executionCount`: Number of function executions that have been completed
84
- * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution
85
- * - `lastArgs`: The arguments from the most recent call to maybeExecute
86
- * - `status`: Current execution status ('disabled' | 'idle' | 'pending')
87
- *
88
- * ## Unmount behavior
89
- *
90
- * By default, the primitive cancels any pending execution when the owning component unmounts.
91
- * Use the `onUnmount` option to customize this. For example, to flush pending work instead:
92
- *
93
- * ```tsx
94
- * const debouncer = createDebouncer(fn, {
95
- * wait: 500,
96
- * onUnmount: (d) => d.flush()
97
- * });
98
- * ```
99
- *
100
- * @example
101
- * ```tsx
102
- * // Default behavior - no reactive state subscriptions
103
- * const debouncer = createDebouncer(
104
- * (query: string) => fetchSearchResults(query),
105
- * { wait: 500 }
106
- * );
107
- *
108
- * // Opt-in to track isPending changes (optimized for loading states)
109
- * const debouncer = createDebouncer(
110
- * (query: string) => fetchSearchResults(query),
111
- * { wait: 500 },
112
- * (state) => ({ isPending: state.isPending })
113
- * );
114
- *
115
- * // Opt-in to track executionCount changes (optimized for tracking execution)
116
- * const debouncer = createDebouncer(
117
- * (query: string) => fetchSearchResults(query),
118
- * { wait: 500 },
119
- * (state) => ({ executionCount: state.executionCount })
120
- * );
121
- *
122
- * // Multiple state properties - track when any of these change
123
- * const debouncer = createDebouncer(
124
- * (query: string) => fetchSearchResults(query),
125
- * { wait: 500 },
126
- * (state) => ({
127
- * isPending: state.isPending,
128
- * executionCount: state.executionCount,
129
- * status: state.status
130
- * })
131
- * );
132
- *
133
- * // In an event handler
134
- * const handleChange = (e) => {
135
- * debouncer.maybeExecute(e.target.value);
136
- * };
137
- *
138
- * // Access the selected state (will be empty object {} unless selector provided)
139
- * const { isPending } = debouncer.state();
140
- * ```
141
- */
142
- declare function createDebouncer<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: SolidDebouncerOptions<TFn, TSelected>, selector?: (state: DebouncerState<TFn>) => TSelected): SolidDebouncer<TFn, TSelected>;
143
- //#endregion
144
- export { SolidDebouncer, SolidDebouncerOptions, createDebouncer };
145
- //# sourceMappingURL=createDebouncer.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { shallow, useSelector } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncerOptions<\n TFn extends AnyFunction,\n TSelected = {},\n> extends DebouncerOptions<TFn> {\n /**\n * Optional callback invoked when the owning component unmounts. Receives the debouncer instance.\n * When provided, replaces the default cleanup (cancel); use it to call flush(), reset(), cancel(), add logging, etc.\n */\n onUnmount?: (debouncer: SolidDebouncer<TFn, TSelected>) => void\n}\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * ## Unmount behavior\n *\n * By default, the primitive cancels any pending execution when the owning component unmounts.\n * Use the `onUnmount` option to customize this. For example, to flush pending work instead:\n *\n * ```tsx\n * const debouncer = createDebouncer(fn, {\n * wait: 500,\n * onUnmount: (d) => d.flush()\n * });\n * ```\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: SolidDebouncerOptions<TFn, TSelected>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as SolidDebouncerOptions<TFn, TSelected>\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useSelector(asyncDebouncer.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(asyncDebouncer.store, selector, {\n compare: shallow,\n })\n\n createEffect(() => {\n onCleanup(() => {\n if (mergedOptions.onUnmount) {\n mergedOptions.onUnmount(asyncDebouncer)\n } else {\n asyncDebouncer.cancel()\n }\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2JA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAChC,MAAM,gBAAgB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ;CACD,MAAM,iBAAiB,IAAI,UACzB,IACA,cACD;CAED,eAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,YAAY,eAAe,OAAO,MAAM,UAAU,EACjE,SAAS,SACV,CAAC;EAEF,OAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,YAAY,eAAe,OAAO,UAAU,EACxD,SAAS,SACV,CAAC;CAEF,mBAAmB;EACjB,gBAAgB;GACd,IAAI,cAAc,WAChB,cAAc,UAAU,eAAe;QAEvC,eAAe,QAAQ;IAEzB;GACF;CAEF,OAAO;EACL,GAAG;EACH;EACD"}
@@ -1,15 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_createDebouncer = require('./createDebouncer.cjs');
3
- const require_createDebouncedSignal = require('./createDebouncedSignal.cjs');
4
- const require_createDebouncedValue = require('./createDebouncedValue.cjs');
5
-
6
- exports.createDebouncedSignal = require_createDebouncedSignal.createDebouncedSignal;
7
- exports.createDebouncedValue = require_createDebouncedValue.createDebouncedValue;
8
- exports.createDebouncer = require_createDebouncer.createDebouncer;
9
- var _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
10
- Object.keys(_tanstack_pacer_debouncer).forEach(function (k) {
11
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
12
- enumerable: true,
13
- get: function () { return _tanstack_pacer_debouncer[k]; }
14
- });
15
- });
@@ -1,5 +0,0 @@
1
- import { SolidDebouncer, SolidDebouncerOptions, createDebouncer } from "./createDebouncer.cjs";
2
- import { createDebouncedSignal } from "./createDebouncedSignal.cjs";
3
- import { createDebouncedValue } from "./createDebouncedValue.cjs";
4
- export * from "@tanstack/pacer/debouncer";
5
- export { SolidDebouncer, SolidDebouncerOptions, createDebouncedSignal, createDebouncedValue, createDebouncer };
package/dist/index.cjs DELETED
@@ -1,47 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_PacerProvider = require('./provider/PacerProvider.cjs');
3
- const require_createAsyncBatcher = require('./async-batcher/createAsyncBatcher.cjs');
4
- const require_createAsyncDebouncer = require('./async-debouncer/createAsyncDebouncer.cjs');
5
- const require_createAsyncQueuer = require('./async-queuer/createAsyncQueuer.cjs');
6
- const require_createAsyncRateLimiter = require('./async-rate-limiter/createAsyncRateLimiter.cjs');
7
- const require_createAsyncThrottler = require('./async-throttler/createAsyncThrottler.cjs');
8
- const require_createBatcher = require('./batcher/createBatcher.cjs');
9
- const require_createDebouncer = require('./debouncer/createDebouncer.cjs');
10
- const require_createDebouncedSignal = require('./debouncer/createDebouncedSignal.cjs');
11
- const require_createDebouncedValue = require('./debouncer/createDebouncedValue.cjs');
12
- const require_createQueuer = require('./queuer/createQueuer.cjs');
13
- const require_createQueuedSignal = require('./queuer/createQueuedSignal.cjs');
14
- const require_createRateLimiter = require('./rate-limiter/createRateLimiter.cjs');
15
- const require_createRateLimitedSignal = require('./rate-limiter/createRateLimitedSignal.cjs');
16
- const require_createRateLimitedValue = require('./rate-limiter/createRateLimitedValue.cjs');
17
- const require_createThrottler = require('./throttler/createThrottler.cjs');
18
- const require_createThrottledSignal = require('./throttler/createThrottledSignal.cjs');
19
- const require_createThrottledValue = require('./throttler/createThrottledValue.cjs');
20
-
21
- exports.PacerProvider = require_PacerProvider.PacerProvider;
22
- exports.createAsyncBatcher = require_createAsyncBatcher.createAsyncBatcher;
23
- exports.createAsyncDebouncer = require_createAsyncDebouncer.createAsyncDebouncer;
24
- exports.createAsyncQueuer = require_createAsyncQueuer.createAsyncQueuer;
25
- exports.createAsyncRateLimiter = require_createAsyncRateLimiter.createAsyncRateLimiter;
26
- exports.createAsyncThrottler = require_createAsyncThrottler.createAsyncThrottler;
27
- exports.createBatcher = require_createBatcher.createBatcher;
28
- exports.createDebouncedSignal = require_createDebouncedSignal.createDebouncedSignal;
29
- exports.createDebouncedValue = require_createDebouncedValue.createDebouncedValue;
30
- exports.createDebouncer = require_createDebouncer.createDebouncer;
31
- exports.createQueuedSignal = require_createQueuedSignal.createQueuedSignal;
32
- exports.createQueuer = require_createQueuer.createQueuer;
33
- exports.createRateLimitedSignal = require_createRateLimitedSignal.createRateLimitedSignal;
34
- exports.createRateLimitedValue = require_createRateLimitedValue.createRateLimitedValue;
35
- exports.createRateLimiter = require_createRateLimiter.createRateLimiter;
36
- exports.createThrottledSignal = require_createThrottledSignal.createThrottledSignal;
37
- exports.createThrottledValue = require_createThrottledValue.createThrottledValue;
38
- exports.createThrottler = require_createThrottler.createThrottler;
39
- exports.useDefaultPacerOptions = require_PacerProvider.useDefaultPacerOptions;
40
- exports.usePacerContext = require_PacerProvider.usePacerContext;
41
- var _tanstack_pacer = require("@tanstack/pacer");
42
- Object.keys(_tanstack_pacer).forEach(function (k) {
43
- if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
44
- enumerable: true,
45
- get: function () { return _tanstack_pacer[k]; }
46
- });
47
- });
package/dist/index.d.cts DELETED
@@ -1,20 +0,0 @@
1
- import { SolidAsyncBatcher, SolidAsyncBatcherOptions, createAsyncBatcher } from "./async-batcher/createAsyncBatcher.cjs";
2
- import { SolidAsyncDebouncer, SolidAsyncDebouncerOptions, createAsyncDebouncer } from "./async-debouncer/createAsyncDebouncer.cjs";
3
- import { SolidAsyncQueuer, SolidAsyncQueuerOptions, createAsyncQueuer } from "./async-queuer/createAsyncQueuer.cjs";
4
- import { SolidAsyncRateLimiter, SolidAsyncRateLimiterOptions, createAsyncRateLimiter } from "./async-rate-limiter/createAsyncRateLimiter.cjs";
5
- import { SolidAsyncThrottler, SolidAsyncThrottlerOptions, createAsyncThrottler } from "./async-throttler/createAsyncThrottler.cjs";
6
- import { SolidBatcher, SolidBatcherOptions, createBatcher } from "./batcher/createBatcher.cjs";
7
- import { SolidDebouncer, SolidDebouncerOptions, createDebouncer } from "./debouncer/createDebouncer.cjs";
8
- import { createDebouncedSignal } from "./debouncer/createDebouncedSignal.cjs";
9
- import { createDebouncedValue } from "./debouncer/createDebouncedValue.cjs";
10
- import { PacerProvider, PacerProviderOptions, PacerProviderProps, useDefaultPacerOptions, usePacerContext } from "./provider/PacerProvider.cjs";
11
- import { SolidQueuer, SolidQueuerOptions, createQueuer } from "./queuer/createQueuer.cjs";
12
- import { createQueuedSignal } from "./queuer/createQueuedSignal.cjs";
13
- import { SolidRateLimiter, SolidRateLimiterOptions, createRateLimiter } from "./rate-limiter/createRateLimiter.cjs";
14
- import { createRateLimitedSignal } from "./rate-limiter/createRateLimitedSignal.cjs";
15
- import { createRateLimitedValue } from "./rate-limiter/createRateLimitedValue.cjs";
16
- import { SolidThrottler, SolidThrottlerOptions, createThrottler } from "./throttler/createThrottler.cjs";
17
- import { createThrottledSignal } from "./throttler/createThrottledSignal.cjs";
18
- import { createThrottledValue } from "./throttler/createThrottledValue.cjs";
19
- export * from "@tanstack/pacer";
20
- export { PacerProvider, PacerProviderOptions, PacerProviderProps, SolidAsyncBatcher, SolidAsyncBatcherOptions, SolidAsyncDebouncer, SolidAsyncDebouncerOptions, SolidAsyncQueuer, SolidAsyncQueuerOptions, SolidAsyncRateLimiter, SolidAsyncRateLimiterOptions, SolidAsyncThrottler, SolidAsyncThrottlerOptions, SolidBatcher, SolidBatcherOptions, SolidDebouncer, SolidDebouncerOptions, SolidQueuer, SolidQueuerOptions, SolidRateLimiter, SolidRateLimiterOptions, SolidThrottler, SolidThrottlerOptions, createAsyncBatcher, createAsyncDebouncer, createAsyncQueuer, createAsyncRateLimiter, createAsyncThrottler, createBatcher, createDebouncedSignal, createDebouncedValue, createDebouncer, createQueuedSignal, createQueuer, createRateLimitedSignal, createRateLimitedValue, createRateLimiter, createThrottledSignal, createThrottledValue, createThrottler, useDefaultPacerOptions, usePacerContext };
@@ -1,27 +0,0 @@
1
- let solid_js_web = require("solid-js/web");
2
- let solid_js = require("solid-js");
3
-
4
- //#region src/provider/PacerProvider.tsx
5
- const PacerContext = (0, solid_js.createContext)(null);
6
- const DEFAULT_OPTIONS = {};
7
- function PacerProvider(props) {
8
- const contextValue = { defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS };
9
- return (0, solid_js_web.createComponent)(PacerContext.Provider, {
10
- value: contextValue,
11
- get children() {
12
- return props.children;
13
- }
14
- });
15
- }
16
- function usePacerContext() {
17
- return (0, solid_js.useContext)(PacerContext);
18
- }
19
- function useDefaultPacerOptions() {
20
- return (0, solid_js.useContext)(PacerContext)?.defaultOptions ?? {};
21
- }
22
-
23
- //#endregion
24
- exports.PacerProvider = PacerProvider;
25
- exports.useDefaultPacerOptions = useDefaultPacerOptions;
26
- exports.usePacerContext = usePacerContext;
27
- //# sourceMappingURL=PacerProvider.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PacerProvider.cjs","names":["createContext","useContext","JSX","AnyAsyncFunction","AnyFunction","AsyncBatcherOptions","AsyncDebouncerOptions","AsyncQueuerOptions","AsyncRateLimiterOptions","AsyncThrottlerOptions","BatcherOptions","DebouncerOptions","QueuerOptions","RateLimiterOptions","ThrottlerOptions","PacerProviderOptions","asyncBatcher","Partial","asyncDebouncer","asyncQueuer","asyncRateLimiter","asyncThrottler","batcher","debouncer","queuer","rateLimiter","throttler","PacerContextValue","defaultOptions","PacerContext","PacerProviderProps","children","Element","DEFAULT_OPTIONS","PacerProvider","props","contextValue","_$createComponent","Provider","value","usePacerContext","useDefaultPacerOptions","context"],"sources":["../../src/provider/PacerProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX } from 'solid-js'\nimport type {\n AnyAsyncFunction,\n AnyFunction,\n AsyncBatcherOptions,\n AsyncDebouncerOptions,\n AsyncQueuerOptions,\n AsyncRateLimiterOptions,\n AsyncThrottlerOptions,\n BatcherOptions,\n DebouncerOptions,\n QueuerOptions,\n RateLimiterOptions,\n ThrottlerOptions,\n} from '@tanstack/pacer'\n\nexport interface PacerProviderOptions {\n asyncBatcher?: Partial<AsyncBatcherOptions<any>>\n asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>\n asyncQueuer?: Partial<AsyncQueuerOptions<any>>\n asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>\n asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>\n batcher?: Partial<BatcherOptions<any>>\n debouncer?: Partial<DebouncerOptions<AnyFunction>>\n queuer?: Partial<QueuerOptions<any>>\n rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>\n throttler?: Partial<ThrottlerOptions<AnyFunction>>\n}\n\ninterface PacerContextValue {\n defaultOptions: PacerProviderOptions\n}\n\nconst PacerContext = createContext<PacerContextValue | null>(null)\n\nexport interface PacerProviderProps {\n children: JSX.Element\n defaultOptions?: PacerProviderOptions\n}\n\nconst DEFAULT_OPTIONS: PacerProviderOptions = {}\n\nexport function PacerProvider(props: PacerProviderProps) {\n const contextValue: PacerContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <PacerContext.Provider value={contextValue}>\n {props.children}\n </PacerContext.Provider>\n )\n}\n\nexport function usePacerContext() {\n return useContext(PacerContext)\n}\n\nexport function useDefaultPacerOptions() {\n const context = useContext(PacerContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAkCA,MAAM6B,2CAAuD,KAAK;AAOlE,MAAMI,kBAAwC,EAAE;AAEhD,SAAgBC,cAAcC,OAA2B;CACvD,MAAMC,eAAkC,EACtCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;CAED,yCACGJ,aAAaS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;GAAA,OACvCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,kBAAkB;CAChC,gCAAkBX,aAAa;;AAGjC,SAAgBY,yBAAyB;CAEvC,gCAD2BZ,aACb,EAAED,kBAAkB,EAAE"}
@@ -1,29 +0,0 @@
1
- import { JSX } from "solid-js";
2
- import { AnyAsyncFunction, AnyFunction, AsyncBatcherOptions, AsyncDebouncerOptions, AsyncQueuerOptions, AsyncRateLimiterOptions, AsyncThrottlerOptions, BatcherOptions, DebouncerOptions, QueuerOptions, RateLimiterOptions, ThrottlerOptions } from "@tanstack/pacer";
3
-
4
- //#region src/provider/PacerProvider.d.ts
5
- interface PacerProviderOptions {
6
- asyncBatcher?: Partial<AsyncBatcherOptions<any>>;
7
- asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>;
8
- asyncQueuer?: Partial<AsyncQueuerOptions<any>>;
9
- asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>;
10
- asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>;
11
- batcher?: Partial<BatcherOptions<any>>;
12
- debouncer?: Partial<DebouncerOptions<AnyFunction>>;
13
- queuer?: Partial<QueuerOptions<any>>;
14
- rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>;
15
- throttler?: Partial<ThrottlerOptions<AnyFunction>>;
16
- }
17
- interface PacerContextValue {
18
- defaultOptions: PacerProviderOptions;
19
- }
20
- interface PacerProviderProps {
21
- children: JSX.Element;
22
- defaultOptions?: PacerProviderOptions;
23
- }
24
- declare function PacerProvider(props: PacerProviderProps): JSX.Element;
25
- declare function usePacerContext(): PacerContextValue | null;
26
- declare function useDefaultPacerOptions(): PacerProviderOptions;
27
- //#endregion
28
- export { PacerProvider, PacerProviderOptions, PacerProviderProps, useDefaultPacerOptions, usePacerContext };
29
- //# sourceMappingURL=PacerProvider.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PacerProvider.js","names":["createContext","useContext","JSX","AnyAsyncFunction","AnyFunction","AsyncBatcherOptions","AsyncDebouncerOptions","AsyncQueuerOptions","AsyncRateLimiterOptions","AsyncThrottlerOptions","BatcherOptions","DebouncerOptions","QueuerOptions","RateLimiterOptions","ThrottlerOptions","PacerProviderOptions","asyncBatcher","Partial","asyncDebouncer","asyncQueuer","asyncRateLimiter","asyncThrottler","batcher","debouncer","queuer","rateLimiter","throttler","PacerContextValue","defaultOptions","PacerContext","PacerProviderProps","children","Element","DEFAULT_OPTIONS","PacerProvider","props","contextValue","_$createComponent","Provider","value","usePacerContext","useDefaultPacerOptions","context"],"sources":["../../src/provider/PacerProvider.tsx"],"sourcesContent":["import { createContext, useContext } from 'solid-js'\nimport type { JSX } from 'solid-js'\nimport type {\n AnyAsyncFunction,\n AnyFunction,\n AsyncBatcherOptions,\n AsyncDebouncerOptions,\n AsyncQueuerOptions,\n AsyncRateLimiterOptions,\n AsyncThrottlerOptions,\n BatcherOptions,\n DebouncerOptions,\n QueuerOptions,\n RateLimiterOptions,\n ThrottlerOptions,\n} from '@tanstack/pacer'\n\nexport interface PacerProviderOptions {\n asyncBatcher?: Partial<AsyncBatcherOptions<any>>\n asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>\n asyncQueuer?: Partial<AsyncQueuerOptions<any>>\n asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>\n asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>\n batcher?: Partial<BatcherOptions<any>>\n debouncer?: Partial<DebouncerOptions<AnyFunction>>\n queuer?: Partial<QueuerOptions<any>>\n rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>\n throttler?: Partial<ThrottlerOptions<AnyFunction>>\n}\n\ninterface PacerContextValue {\n defaultOptions: PacerProviderOptions\n}\n\nconst PacerContext = createContext<PacerContextValue | null>(null)\n\nexport interface PacerProviderProps {\n children: JSX.Element\n defaultOptions?: PacerProviderOptions\n}\n\nconst DEFAULT_OPTIONS: PacerProviderOptions = {}\n\nexport function PacerProvider(props: PacerProviderProps) {\n const contextValue: PacerContextValue = {\n defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,\n }\n\n return (\n <PacerContext.Provider value={contextValue}>\n {props.children}\n </PacerContext.Provider>\n )\n}\n\nexport function usePacerContext() {\n return useContext(PacerContext)\n}\n\nexport function useDefaultPacerOptions() {\n const context = useContext(PacerContext)\n return context?.defaultOptions ?? {}\n}\n"],"mappings":";;;;AAkCA,MAAM6B,eAAe7B,cAAwC,KAAK;AAOlE,MAAMiC,kBAAwC,EAAE;AAEhD,SAAgBC,cAAcC,OAA2B;CACvD,MAAMC,eAAkC,EACtCR,gBAAgBO,MAAMP,kBAAkBK,iBACzC;CAED,OAAAI,gBACGR,aAAaS,UAAQ;EAACC,OAAOH;EAAY,IAAAL,WAAA;GAAA,OACvCI,MAAMJ;;EAAQ,CAAA;;AAKrB,SAAgBS,kBAAkB;CAChC,OAAOvC,WAAW4B,aAAa;;AAGjC,SAAgBY,yBAAyB;CAEvC,OADgBxC,WAAW4B,aACb,EAAED,kBAAkB,EAAE"}
@@ -1,6 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
- const require_PacerProvider = require('./PacerProvider.cjs');
3
-
4
- exports.PacerProvider = require_PacerProvider.PacerProvider;
5
- exports.useDefaultPacerOptions = require_PacerProvider.useDefaultPacerOptions;
6
- exports.usePacerContext = require_PacerProvider.usePacerContext;
@@ -1,2 +0,0 @@
1
- import { PacerProvider, PacerProviderOptions, PacerProviderProps, useDefaultPacerOptions, usePacerContext } from "./PacerProvider.cjs";
2
- export { PacerProvider, PacerProviderOptions, PacerProviderProps, useDefaultPacerOptions, usePacerContext };
@@ -1,129 +0,0 @@
1
- const require_createQueuer = require('./createQueuer.cjs');
2
-
3
- //#region src/queuer/createQueuedSignal.ts
4
- /**
5
- * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.
6
- * This primitive provides both the current queue state and queue control methods.
7
- *
8
- * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
9
- * All queue operations are reflected in the state array returned by the primitive.
10
- *
11
- * The queue can be started and stopped to automatically process items at a specified interval,
12
- * making it useful as a scheduler. When started, it will process one item per tick, with an
13
- * optional wait time between ticks.
14
- *
15
- * The primitive returns a tuple containing:
16
- * - The current queue state as an array
17
- * - The queue instance with methods for queue manipulation
18
- *
19
- * ## State Management and Selector
20
- *
21
- * The primitive uses Solid's reactive state management via the underlying queuer instance.
22
- * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
23
- * optimizing performance by preventing unnecessary updates 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 updates and gives you
27
- * full control over when your component tracks state changes. Only when you provide a selector will the
28
- * component track changes to the selected state values.
29
- *
30
- * Available queuer state properties:
31
- * - `executionCount`: Number of items that have been processed by the queuer
32
- * - `expirationCount`: Number of items that have been removed due to expiration
33
- * - `isEmpty`: Whether the queuer has no items to process
34
- * - `isFull`: Whether the queuer has reached its maximum capacity
35
- * - `isIdle`: Whether the queuer is not currently processing any items
36
- * - `isRunning`: Whether the queuer is active and will process items automatically
37
- * - `items`: Array of items currently waiting to be processed
38
- * - `itemTimestamps`: Timestamps when items were added for expiration tracking
39
- * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
40
- * - `rejectionCount`: Number of items that have been rejected from being added
41
- * - `size`: Number of items currently in the queue
42
- * - `status`: Current processing status ('idle' | 'running' | 'stopped')
43
- *
44
- * @example
45
- * ```tsx
46
- * // Default behavior - no reactive state subscriptions
47
- * const [items, addItem, queue] = createQueuedSignal(
48
- * (item) => console.log('Processing:', item),
49
- * {
50
- * initialItems: ['item1', 'item2'],
51
- * started: true,
52
- * wait: 1000,
53
- * getPriority: (item) => item.priority
54
- * }
55
- * );
56
- *
57
- * // Opt-in to track queue contents changes (optimized for displaying queue items)
58
- * const [items, addItem, queue] = createQueuedSignal(
59
- * (item) => console.log('Processing:', item),
60
- * { started: true, wait: 1000 },
61
- * (state) => ({
62
- * items: state.items,
63
- * size: state.size,
64
- * isEmpty: state.isEmpty
65
- * })
66
- * );
67
- *
68
- * // Opt-in to track processing state changes (optimized for loading indicators)
69
- * const [items, addItem, queue] = createQueuedSignal(
70
- * (item) => console.log('Processing:', item),
71
- * { started: true, wait: 1000 },
72
- * (state) => ({
73
- * isRunning: state.isRunning,
74
- * isIdle: state.isIdle,
75
- * status: state.status,
76
- * pendingTick: state.pendingTick
77
- * })
78
- * );
79
- *
80
- * // Opt-in to track execution metrics changes (optimized for stats display)
81
- * const [items, addItem, queue] = createQueuedSignal(
82
- * (item) => console.log('Processing:', item),
83
- * { started: true, wait: 1000 },
84
- * (state) => ({
85
- * executionCount: state.executionCount,
86
- * expirationCount: state.expirationCount,
87
- * rejectionCount: state.rejectionCount
88
- * })
89
- * );
90
- *
91
- * // Add items to queue
92
- * const handleAdd = (item) => {
93
- * addItem(item);
94
- * };
95
- *
96
- * // Start automatic processing
97
- * const startProcessing = () => {
98
- * queue.start();
99
- * };
100
- *
101
- * // Stop automatic processing
102
- * const stopProcessing = () => {
103
- * queue.stop();
104
- * };
105
- *
106
- * // Manual processing still available
107
- * const handleProcess = () => {
108
- * const nextItem = queue.getNextItem();
109
- * if (nextItem) {
110
- * processItem(nextItem);
111
- * }
112
- * };
113
- *
114
- * // Access the selected queuer state (will be empty object {} unless selector provided)
115
- * const { size, isRunning, executionCount } = queue.state;
116
- * ```
117
- */
118
- function createQueuedSignal(fn, options = {}, selector = (state) => ({ items: state.items })) {
119
- const queue = require_createQueuer.createQueuer(fn, options, selector);
120
- return [
121
- () => queue.state().items,
122
- queue.addItem,
123
- queue
124
- ];
125
- }
126
-
127
- //#endregion
128
- exports.createQueuedSignal = createQueuedSignal;
129
- //# sourceMappingURL=createQueuedSignal.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"createQueuedSignal.cjs","names":["createQueuer"],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer, SolidQueuerOptions } from './createQueuer'\nimport type { QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary updates 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 updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will the\n * component track changes to the selected state values.\n *\n * Available queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to track queue contents changes (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to track processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: SolidQueuerOptions<TValue, TSelected> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiD,EAAE,EACnD,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQA,kCAAa,IAAI,SAAS,SAAS;CAEjD,OAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}