@tanstack/solid-pacer 0.17.0 → 0.18.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/dist/async-batcher/createAsyncBatcher.cjs +26 -12
  2. package/dist/async-batcher/createAsyncBatcher.cjs.map +1 -1
  3. package/dist/async-batcher/createAsyncBatcher.d.cts +36 -9
  4. package/dist/async-batcher/createAsyncBatcher.d.ts +36 -9
  5. package/dist/async-batcher/createAsyncBatcher.js +22 -8
  6. package/dist/async-batcher/createAsyncBatcher.js.map +1 -1
  7. package/dist/async-batcher/index.cjs +3 -3
  8. package/dist/async-debouncer/createAsyncDebouncer.cjs +26 -12
  9. package/dist/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  10. package/dist/async-debouncer/createAsyncDebouncer.d.cts +36 -9
  11. package/dist/async-debouncer/createAsyncDebouncer.d.ts +36 -9
  12. package/dist/async-debouncer/createAsyncDebouncer.js +22 -8
  13. package/dist/async-debouncer/createAsyncDebouncer.js.map +1 -1
  14. package/dist/async-debouncer/index.cjs +3 -3
  15. package/dist/async-queuer/createAsyncQueuer.cjs +26 -12
  16. package/dist/async-queuer/createAsyncQueuer.cjs.map +1 -1
  17. package/dist/async-queuer/createAsyncQueuer.d.cts +36 -9
  18. package/dist/async-queuer/createAsyncQueuer.d.ts +36 -9
  19. package/dist/async-queuer/createAsyncQueuer.js +22 -8
  20. package/dist/async-queuer/createAsyncQueuer.js.map +1 -1
  21. package/dist/async-queuer/index.cjs +3 -3
  22. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs +89 -30
  23. package/dist/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  24. package/dist/async-rate-limiter/createAsyncRateLimiter.d.cts +99 -27
  25. package/dist/async-rate-limiter/createAsyncRateLimiter.d.ts +99 -27
  26. package/dist/async-rate-limiter/createAsyncRateLimiter.js +85 -26
  27. package/dist/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  28. package/dist/async-rate-limiter/index.cjs +3 -3
  29. package/dist/async-throttler/createAsyncThrottler.cjs +26 -12
  30. package/dist/async-throttler/createAsyncThrottler.cjs.map +1 -1
  31. package/dist/async-throttler/createAsyncThrottler.d.cts +36 -9
  32. package/dist/async-throttler/createAsyncThrottler.d.ts +36 -9
  33. package/dist/async-throttler/createAsyncThrottler.js +22 -8
  34. package/dist/async-throttler/createAsyncThrottler.js.map +1 -1
  35. package/dist/async-throttler/index.cjs +3 -3
  36. package/dist/batcher/createBatcher.cjs +26 -12
  37. package/dist/batcher/createBatcher.cjs.map +1 -1
  38. package/dist/batcher/createBatcher.d.cts +36 -9
  39. package/dist/batcher/createBatcher.d.ts +36 -9
  40. package/dist/batcher/createBatcher.js +22 -8
  41. package/dist/batcher/createBatcher.js.map +1 -1
  42. package/dist/batcher/index.cjs +3 -3
  43. package/dist/debouncer/createDebouncer.cjs +27 -13
  44. package/dist/debouncer/createDebouncer.cjs.map +1 -1
  45. package/dist/debouncer/createDebouncer.d.cts +37 -10
  46. package/dist/debouncer/createDebouncer.d.ts +37 -10
  47. package/dist/debouncer/createDebouncer.js +23 -9
  48. package/dist/debouncer/createDebouncer.js.map +1 -1
  49. package/dist/debouncer/index.cjs +3 -3
  50. package/dist/index.cjs +3 -3
  51. package/dist/queuer/createQueuedSignal.cjs +8 -8
  52. package/dist/queuer/createQueuedSignal.cjs.map +1 -1
  53. package/dist/queuer/createQueuedSignal.d.cts +8 -8
  54. package/dist/queuer/createQueuedSignal.d.ts +8 -8
  55. package/dist/queuer/createQueuedSignal.js +8 -8
  56. package/dist/queuer/createQueuedSignal.js.map +1 -1
  57. package/dist/queuer/createQueuer.cjs +26 -12
  58. package/dist/queuer/createQueuer.cjs.map +1 -1
  59. package/dist/queuer/createQueuer.d.cts +36 -9
  60. package/dist/queuer/createQueuer.d.ts +36 -9
  61. package/dist/queuer/createQueuer.js +22 -8
  62. package/dist/queuer/createQueuer.js.map +1 -1
  63. package/dist/queuer/index.cjs +3 -3
  64. package/dist/rate-limiter/createRateLimiter.cjs +78 -23
  65. package/dist/rate-limiter/createRateLimiter.cjs.map +1 -1
  66. package/dist/rate-limiter/createRateLimiter.d.cts +88 -20
  67. package/dist/rate-limiter/createRateLimiter.d.ts +88 -20
  68. package/dist/rate-limiter/createRateLimiter.js +74 -19
  69. package/dist/rate-limiter/createRateLimiter.js.map +1 -1
  70. package/dist/rate-limiter/index.cjs +3 -3
  71. package/dist/throttler/createThrottledSignal.cjs +1 -1
  72. package/dist/throttler/createThrottledSignal.cjs.map +1 -1
  73. package/dist/throttler/createThrottledSignal.d.cts +1 -1
  74. package/dist/throttler/createThrottledSignal.d.ts +1 -1
  75. package/dist/throttler/createThrottledSignal.js +1 -1
  76. package/dist/throttler/createThrottledSignal.js.map +1 -1
  77. package/dist/throttler/createThrottledValue.cjs +1 -1
  78. package/dist/throttler/createThrottledValue.cjs.map +1 -1
  79. package/dist/throttler/createThrottledValue.d.cts +1 -1
  80. package/dist/throttler/createThrottledValue.d.ts +1 -1
  81. package/dist/throttler/createThrottledValue.js +1 -1
  82. package/dist/throttler/createThrottledValue.js.map +1 -1
  83. package/dist/throttler/createThrottler.cjs +34 -13
  84. package/dist/throttler/createThrottler.cjs.map +1 -1
  85. package/dist/throttler/createThrottler.d.cts +44 -10
  86. package/dist/throttler/createThrottler.d.ts +44 -10
  87. package/dist/throttler/createThrottler.js +30 -9
  88. package/dist/throttler/createThrottler.js.map +1 -1
  89. package/dist/throttler/index.cjs +3 -3
  90. package/dist/types/index.cjs +3 -3
  91. package/dist/utils/index.cjs +3 -3
  92. package/package.json +2 -2
  93. package/src/async-batcher/createAsyncBatcher.ts +51 -10
  94. package/src/async-debouncer/createAsyncDebouncer.ts +51 -10
  95. package/src/async-queuer/createAsyncQueuer.ts +51 -10
  96. package/src/async-rate-limiter/createAsyncRateLimiter.ts +114 -28
  97. package/src/async-throttler/createAsyncThrottler.ts +51 -10
  98. package/src/batcher/createBatcher.ts +51 -10
  99. package/src/debouncer/createDebouncer.ts +52 -11
  100. package/src/queuer/createQueuedSignal.ts +8 -8
  101. package/src/queuer/createQueuer.ts +51 -10
  102. package/src/rate-limiter/createRateLimiter.ts +103 -21
  103. package/src/throttler/createThrottledSignal.ts +1 -1
  104. package/src/throttler/createThrottledValue.ts +1 -1
  105. package/src/throttler/createThrottler.ts +59 -11
@@ -1,10 +1,27 @@
1
- import { Accessor } from "solid-js";
1
+ import { Accessor, JSX } from "solid-js";
2
2
  import { Store } from "@tanstack/solid-store";
3
3
  import { RateLimiter, RateLimiterOptions, RateLimiterState } from "@tanstack/pacer/rate-limiter";
4
4
  import { AnyFunction } from "@tanstack/pacer/types";
5
5
 
6
6
  //#region src/rate-limiter/createRateLimiter.d.ts
7
7
  interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit<RateLimiter<TFn>, 'store'> {
8
+ /**
9
+ * A Solid component that allows you to subscribe to the rate limiter state.
10
+ *
11
+ * This is useful for tracking specific parts of the rate limiter state
12
+ * deep in your component tree without needing to pass a selector to the hook.
13
+ *
14
+ * @example
15
+ * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
16
+ * {(state) => (
17
+ * <div>Rejections: {state().rejectionCount}</div>
18
+ * )}
19
+ * </rateLimiter.Subscribe>
20
+ */
21
+ Subscribe: <TSelected>(props: {
22
+ selector: (state: RateLimiterState) => TSelected;
23
+ children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
24
+ }) => JSX.Element;
8
25
  /**
9
26
  * Reactive state that will be updated when the rate limiter state changes
10
27
  *
@@ -41,14 +58,24 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
41
58
  *
42
59
  * ## State Management and Selector
43
60
  *
44
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
45
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
46
- * unnecessary re-renders when irrelevant state changes occur.
61
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
62
+ * in two ways:
63
+ *
64
+ * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
65
+ *
66
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
67
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
68
+ * in child components.
69
+ *
70
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
71
+ *
72
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
73
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
74
+ * state changes occur.
47
75
  *
48
76
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
49
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
50
- * full control over when your component updates. Only when you provide a selector will the
51
- * component re-render when the selected state values change.
77
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
78
+ * updates and gives you full control over when your component tracks state changes.
52
79
  *
53
80
  * Available state properties:
54
81
  * - `executionCount`: Number of function executions that have been completed
@@ -64,33 +91,74 @@ interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}> extends Omit
64
91
  * limit: 5,
65
92
  * window: 60000,
66
93
  * windowType: 'sliding',
67
- * onReject: (rateLimiter) => {
68
- * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
69
- * }
70
94
  * });
71
95
  *
72
- * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)
96
+ * // Subscribe to state changes deep in component tree using Subscribe component
97
+ * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
98
+ * {(state) => (
99
+ * <div>Rejections: {state().rejectionCount}</div>
100
+ * )}
101
+ * </rateLimiter.Subscribe>
102
+ *
103
+ * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)
73
104
  * const rateLimiter = createRateLimiter(
74
105
  * apiCall,
75
- * { limit: 5, window: 60000 },
76
- * (state) => ({
77
- * remainingInWindow: state.remainingInWindow,
78
- * rejectionCount: state.rejectionCount
79
- * })
106
+ * {
107
+ * limit: 5,
108
+ * window: 60000,
109
+ * windowType: 'sliding',
110
+ * },
111
+ * (state) => ({ executionCount: state.executionCount })
112
+ * );
113
+ *
114
+ * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)
115
+ * const rateLimiter = createRateLimiter(
116
+ * apiCall,
117
+ * {
118
+ * limit: 5,
119
+ * window: 60000,
120
+ * windowType: 'sliding',
121
+ * },
122
+ * (state) => ({ rejectionCount: state.rejectionCount })
123
+ * );
124
+ *
125
+ * // Opt-in to track execution times changes (optimized for window calculations)
126
+ * const rateLimiter = createRateLimiter(
127
+ * apiCall,
128
+ * {
129
+ * limit: 5,
130
+ * window: 60000,
131
+ * windowType: 'sliding',
132
+ * },
133
+ * (state) => ({ executionTimes: state.executionTimes })
80
134
  * );
81
135
  *
82
- * // Opt-in to re-render when execution metrics change (optimized for tracking progress)
136
+ * // Multiple state properties - track when any of these change
83
137
  * const rateLimiter = createRateLimiter(
84
138
  * apiCall,
85
- * { limit: 5, window: 60000 },
139
+ * {
140
+ * limit: 5,
141
+ * window: 60000,
142
+ * windowType: 'sliding',
143
+ * },
86
144
  * (state) => ({
87
145
  * executionCount: state.executionCount,
88
- * nextWindowTime: state.nextWindowTime
146
+ * rejectionCount: state.rejectionCount
89
147
  * })
90
148
  * );
91
149
  *
150
+ * // Monitor rate limit status
151
+ * const handleClick = () => {
152
+ * const remaining = rateLimiter.getRemainingInWindow();
153
+ * if (remaining > 0) {
154
+ * rateLimiter.maybeExecute(data);
155
+ * } else {
156
+ * showRateLimitWarning();
157
+ * }
158
+ * };
159
+ *
92
160
  * // Access the selected state (will be empty object {} unless selector provided)
93
- * const { remainingInWindow, rejectionCount } = rateLimiter.state();
161
+ * const { executionCount, rejectionCount } = rateLimiter.state();
94
162
  * ```
95
163
  */
96
164
  declare function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(fn: TFn, options: RateLimiterOptions<TFn>, selector?: (state: RateLimiterState) => TSelected): SolidRateLimiter<TFn, TSelected>;
@@ -26,14 +26,24 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
26
26
  *
27
27
  * ## State Management and Selector
28
28
  *
29
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
30
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
31
- * unnecessary re-renders when irrelevant state changes occur.
29
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
30
+ * in two ways:
31
+ *
32
+ * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**
33
+ *
34
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
35
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
36
+ * in child components.
37
+ *
38
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
39
+ *
40
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
41
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
42
+ * state changes occur.
32
43
  *
33
44
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
34
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
35
- * full control over when your component updates. Only when you provide a selector will the
36
- * component re-render when the selected state values change.
45
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
46
+ * updates and gives you full control over when your component tracks state changes.
37
47
  *
38
48
  * Available state properties:
39
49
  * - `executionCount`: Number of function executions that have been completed
@@ -49,33 +59,74 @@ import { RateLimiter } from "@tanstack/pacer/rate-limiter";
49
59
  * limit: 5,
50
60
  * window: 60000,
51
61
  * windowType: 'sliding',
52
- * onReject: (rateLimiter) => {
53
- * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
54
- * }
55
62
  * });
56
63
  *
57
- * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)
64
+ * // Subscribe to state changes deep in component tree using Subscribe component
65
+ * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>
66
+ * {(state) => (
67
+ * <div>Rejections: {state().rejectionCount}</div>
68
+ * )}
69
+ * </rateLimiter.Subscribe>
70
+ *
71
+ * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)
58
72
  * const rateLimiter = createRateLimiter(
59
73
  * apiCall,
60
- * { limit: 5, window: 60000 },
61
- * (state) => ({
62
- * remainingInWindow: state.remainingInWindow,
63
- * rejectionCount: state.rejectionCount
64
- * })
74
+ * {
75
+ * limit: 5,
76
+ * window: 60000,
77
+ * windowType: 'sliding',
78
+ * },
79
+ * (state) => ({ executionCount: state.executionCount })
65
80
  * );
66
81
  *
67
- * // Opt-in to re-render when execution metrics change (optimized for tracking progress)
82
+ * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)
68
83
  * const rateLimiter = createRateLimiter(
69
84
  * apiCall,
70
- * { limit: 5, window: 60000 },
85
+ * {
86
+ * limit: 5,
87
+ * window: 60000,
88
+ * windowType: 'sliding',
89
+ * },
90
+ * (state) => ({ rejectionCount: state.rejectionCount })
91
+ * );
92
+ *
93
+ * // Opt-in to track execution times changes (optimized for window calculations)
94
+ * const rateLimiter = createRateLimiter(
95
+ * apiCall,
96
+ * {
97
+ * limit: 5,
98
+ * window: 60000,
99
+ * windowType: 'sliding',
100
+ * },
101
+ * (state) => ({ executionTimes: state.executionTimes })
102
+ * );
103
+ *
104
+ * // Multiple state properties - track when any of these change
105
+ * const rateLimiter = createRateLimiter(
106
+ * apiCall,
107
+ * {
108
+ * limit: 5,
109
+ * window: 60000,
110
+ * windowType: 'sliding',
111
+ * },
71
112
  * (state) => ({
72
113
  * executionCount: state.executionCount,
73
- * nextWindowTime: state.nextWindowTime
114
+ * rejectionCount: state.rejectionCount
74
115
  * })
75
116
  * );
76
117
  *
118
+ * // Monitor rate limit status
119
+ * const handleClick = () => {
120
+ * const remaining = rateLimiter.getRemainingInWindow();
121
+ * if (remaining > 0) {
122
+ * rateLimiter.maybeExecute(data);
123
+ * } else {
124
+ * showRateLimitWarning();
125
+ * }
126
+ * };
127
+ *
77
128
  * // Access the selected state (will be empty object {} unless selector provided)
78
- * const { remainingInWindow, rejectionCount } = rateLimiter.state();
129
+ * const { executionCount, rejectionCount } = rateLimiter.state();
79
130
  * ```
80
131
  */
81
132
  function createRateLimiter(fn, options, selector = () => ({})) {
@@ -83,6 +134,10 @@ function createRateLimiter(fn, options, selector = () => ({})) {
83
134
  ...useDefaultPacerOptions().rateLimiter,
84
135
  ...options
85
136
  });
137
+ rateLimiter.Subscribe = function Subscribe(props) {
138
+ const selected = useStore(rateLimiter.store, props.selector);
139
+ return typeof props.children === "function" ? props.children(selected) : props.children;
140
+ };
86
141
  const state = useStore(rateLimiter.store, selector);
87
142
  return {
88
143
  ...rateLimiter,
@@ -1 +1 @@
1
- {"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders 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 re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * onReject: (rateLimiter) => {\n * console.log(`Rate limit exceeded. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);\n * }\n * });\n *\n * // Opt-in to re-render when rate limit state changes (optimized for UI feedback)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * remainingInWindow: state.remainingInWindow,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * { limit: 5, window: 60000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * nextWindowTime: state.nextWindowTime\n * })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { remainingInWindow, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)\n\n const state = useStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwGA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAMlC,MAAM,cAAc,IAAI,YAAiB,IALnB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE0D;CAE3D,MAAM,QAAQ,SAAS,YAAY,OAAO,SAAS;AAEnD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createRateLimiter.js","names":[],"sources":["../../src/rate-limiter/createRateLimiter.ts"],"sourcesContent":["import { RateLimiter } from '@tanstack/pacer/rate-limiter'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n RateLimiterOptions,\n RateLimiterState,\n} from '@tanstack/pacer/rate-limiter'\n\nexport interface SolidRateLimiter<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<RateLimiter<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the rate limiter state.\n *\n * This is useful for tracking specific parts of the rate limiter state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the rate limiter state changes\n *\n * Use this instead of `rateLimiter.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `rateLimiter.state` instead of `rateLimiter.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `useStore` hook internally.\n * Although, you can make the state reactive by using the `useStore` in your own usage.\n */\n readonly store: Store<Readonly<RateLimiterState>>\n}\n\n/**\n * A low-level Solid hook that creates a `RateLimiter` instance to enforce rate limits on function execution.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a rate limiter instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Rate limiting is a simple \"hard limit\" approach that allows executions until a maximum count is reached within\n * a time window, then blocks all subsequent calls until the window resets. Unlike throttling or debouncing,\n * it does not attempt to space out or collapse executions intelligently.\n *\n * The rate limiter supports two types of windows:\n * - 'fixed': A strict window that resets after the window period. All executions within the window count\n * towards the limit, and the window resets completely after the period.\n * - 'sliding': A rolling window that allows executions as old ones expire. This provides a more\n * consistent rate of execution over time.\n *\n * For smoother execution patterns:\n * - Use throttling when you want consistent spacing between executions (e.g. UI updates)\n * - Use debouncing when you want to collapse rapid-fire events (e.g. search input)\n * - Use rate limiting only when you need to enforce hard limits (e.g. API rate limits)\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `rateLimiter.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of function executions that have been completed\n * - `rejectionCount`: Number of function calls that were rejected due to rate limiting\n * - `remainingInWindow`: Number of executions remaining in the current window\n * - `nextWindowTime`: Timestamp when the next window begins\n * - `currentWindowStart`: Timestamp when the current window started\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const rateLimiter = createRateLimiter(apiCall, {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * });\n *\n * // Subscribe to state changes deep in component tree using Subscribe component\n * <rateLimiter.Subscribe selector={(state) => ({ rejectionCount: state.rejectionCount })}>\n * {(state) => (\n * <div>Rejections: {state().rejectionCount}</div>\n * )}\n * </rateLimiter.Subscribe>\n *\n * // Opt-in to track execution count changes at hook level (optimized for tracking successful executions)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Opt-in to track rejection count changes (optimized for tracking rate limit violations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ rejectionCount: state.rejectionCount })\n * );\n *\n * // Opt-in to track execution times changes (optimized for window calculations)\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({ executionTimes: state.executionTimes })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const rateLimiter = createRateLimiter(\n * apiCall,\n * {\n * limit: 5,\n * window: 60000,\n * windowType: 'sliding',\n * },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Monitor rate limit status\n * const handleClick = () => {\n * const remaining = rateLimiter.getRemainingInWindow();\n * if (remaining > 0) {\n * rateLimiter.maybeExecute(data);\n * } else {\n * showRateLimitWarning();\n * }\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { executionCount, rejectionCount } = rateLimiter.state();\n * ```\n */\nexport function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: RateLimiterOptions<TFn>,\n selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,\n): SolidRateLimiter<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().rateLimiter,\n ...options,\n } as RateLimiterOptions<TFn>\n\n const rateLimiter = new RateLimiter<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidRateLimiter<TFn, TSelected>\n\n rateLimiter.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: RateLimiterState) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(rateLimiter.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(rateLimiter.store, selector)\n\n return {\n ...rateLimiter,\n state,\n } as SolidRateLimiter<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4KA,SAAgB,kBACd,IACA,SACA,kBAA0D,EAAE,GAC1B;CAMlC,MAAM,cAAc,IAAI,YACtB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,aAAY,YAAY,SAAS,UAAqB,OAGnD;EACD,MAAM,WAAW,SAAS,YAAY,OAAO,MAAM,SAAS;AAE5D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,YAAY,OAAO,SAAS;AAEnD,QAAO;EACL,GAAG;EACH;EACD"}
@@ -5,10 +5,10 @@ const require_createRateLimitedValue = require('./createRateLimitedValue.cjs');
5
5
  exports.createRateLimitedSignal = require_createRateLimitedSignal.createRateLimitedSignal;
6
6
  exports.createRateLimitedValue = require_createRateLimitedValue.createRateLimitedValue;
7
7
  exports.createRateLimiter = require_createRateLimiter.createRateLimiter;
8
- var __tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
9
- Object.keys(__tanstack_pacer_rate_limiter).forEach(function (k) {
8
+ var _tanstack_pacer_rate_limiter = require("@tanstack/pacer/rate-limiter");
9
+ Object.keys(_tanstack_pacer_rate_limiter).forEach(function (k) {
10
10
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11
11
  enumerable: true,
12
- get: function () { return __tanstack_pacer_rate_limiter[k]; }
12
+ get: function () { return _tanstack_pacer_rate_limiter[k]; }
13
13
  });
14
14
  });
@@ -7,7 +7,7 @@ let solid_js = require("solid-js");
7
7
  * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
8
8
  *
9
9
  * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
10
- * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.
10
+ * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
11
11
  *
12
12
  * The hook returns a tuple containing:
13
13
  * - The throttled state value accessor
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.cjs","names":["createThrottler"],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,gDAA0C,MAAM;CACvE,MAAM,YAAYA,wCAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
1
+ {"version":3,"file":"createThrottledSignal.cjs","names":["createThrottler"],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,gDAA0C,MAAM;CACvE,MAAM,YAAYA,wCAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
@@ -9,7 +9,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
9
9
  * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
10
10
  *
11
11
  * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
12
- * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.
12
+ * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
13
13
  *
14
14
  * The hook returns a tuple containing:
15
15
  * - The throttled state value accessor
@@ -9,7 +9,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
9
9
  * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
10
10
  *
11
11
  * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
12
- * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.
12
+ * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
13
13
  *
14
14
  * The hook returns a tuple containing:
15
15
  * - The throttled state value accessor
@@ -7,7 +7,7 @@ import { createSignal } from "solid-js";
7
7
  * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.
8
8
  *
9
9
  * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.
10
- * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.
10
+ * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.
11
11
  *
12
12
  * The hook returns a tuple containing:
13
13
  * - The throttled state value accessor
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledSignal.js","names":[],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive re-renders or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,MAAM;CACvE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
1
+ {"version":3,"file":"createThrottledSignal.js","names":[],"sources":["../../src/throttler/createThrottledSignal.ts"],"sourcesContent":["import { createSignal } from 'solid-js'\nimport { createThrottler } from './createThrottler'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A Solid hook that creates a throttled state value that updates at most once within a specified time window.\n * This hook combines Solid's createSignal with throttling functionality to provide controlled state updates.\n *\n * Throttling ensures state updates occur at a controlled rate regardless of how frequently the setter is called.\n * This is useful for rate-limiting expensive updates or operations that depend on rapidly changing state.\n *\n * The hook returns a tuple containing:\n * - The throttled state value accessor\n * - A throttled setter function that respects the configured wait time\n * - The throttler instance for additional control\n *\n * For more direct control over throttling without state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [value, setValue, throttler] = createThrottledSignal(0, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [value, setValue, throttler] = createThrottledSignal(\n * 0,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // With custom leading/trailing behavior\n * const [value, setValue] = createThrottledSignal(0, {\n * wait: 1000,\n * leading: true, // Update immediately on first change\n * trailing: false // Skip trailing edge updates\n * });\n *\n * // Access throttler state via signals\n * console.log('Executions:', throttler.state().executionCount);\n * console.log('Is pending:', throttler.state().isPending);\n * console.log('Last execution:', throttler.state().lastExecutionTime);\n * console.log('Next execution:', throttler.state().nextExecutionTime);\n * ```\n */\nexport function createThrottledSignal<TValue, TSelected = {}>(\n value: TValue,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [\n Accessor<TValue>,\n Setter<TValue>,\n SolidThrottler<Setter<TValue>, TSelected>,\n] {\n const [throttledValue, setThrottledValue] = createSignal<TValue>(value)\n const throttler = createThrottler(setThrottledValue, initialOptions, selector)\n return [throttledValue, throttler.maybeExecute as Setter<TValue>, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuEA,SAAgB,sBACd,OACA,gBACA,UAKA;CACA,MAAM,CAAC,gBAAgB,qBAAqB,aAAqB,MAAM;CACvE,MAAM,YAAY,gBAAgB,mBAAmB,gBAAgB,SAAS;AAC9E,QAAO;EAAC;EAAgB,UAAU;EAAgC;EAAU"}
@@ -7,7 +7,7 @@ let solid_js = require("solid-js");
7
7
  * This hook uses Solid's createSignal internally to manage the throttled state.
8
8
  *
9
9
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
10
- * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
10
+ * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
11
11
  *
12
12
  * The hook returns a tuple containing:
13
13
  * - An accessor function that provides the throttled value
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledValue.cjs","names":["createThrottledSignal"],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,OAAO,EACP,gBACA,SACD;AAED,kCAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
1
+ {"version":3,"file":"createThrottledValue.cjs","names":["createThrottledSignal"],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAaA,oDACrD,OAAO,EACP,gBACA,SACD;AAED,kCAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
@@ -9,7 +9,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
9
9
  * This hook uses Solid's createSignal internally to manage the throttled state.
10
10
  *
11
11
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
12
- * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
12
+ * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
13
13
  *
14
14
  * The hook returns a tuple containing:
15
15
  * - An accessor function that provides the throttled value
@@ -9,7 +9,7 @@ import { ThrottlerOptions, ThrottlerState } from "@tanstack/pacer/throttler";
9
9
  * This hook uses Solid's createSignal internally to manage the throttled state.
10
10
  *
11
11
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
12
- * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
12
+ * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
13
13
  *
14
14
  * The hook returns a tuple containing:
15
15
  * - An accessor function that provides the throttled value
@@ -7,7 +7,7 @@ import { createEffect } from "solid-js";
7
7
  * This hook uses Solid's createSignal internally to manage the throttled state.
8
8
  *
9
9
  * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.
10
- * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.
10
+ * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.
11
11
  *
12
12
  * The hook returns a tuple containing:
13
13
  * - An accessor function that provides the throttled value
@@ -1 +1 @@
1
- {"version":3,"file":"createThrottledValue.js","names":[],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive re-renders or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,OAAO,EACP,gBACA,SACD;AAED,oBAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
1
+ {"version":3,"file":"createThrottledValue.js","names":[],"sources":["../../src/throttler/createThrottledValue.ts"],"sourcesContent":["import { createEffect } from 'solid-js'\nimport { createThrottledSignal } from './createThrottledSignal'\nimport type { SolidThrottler } from './createThrottler'\nimport type { Accessor, Setter } from 'solid-js'\nimport type {\n ThrottlerOptions,\n ThrottlerState,\n} from '@tanstack/pacer/throttler'\n\n/**\n * A high-level Solid hook that creates a throttled version of a value that updates at most once within a specified time window.\n * This hook uses Solid's createSignal internally to manage the throttled state.\n *\n * Throttling ensures the value updates occur at a controlled rate regardless of how frequently the input value changes.\n * This is useful for rate-limiting expensive updates or API calls that depend on rapidly changing values.\n *\n * The hook returns a tuple containing:\n * - An accessor function that provides the throttled value\n * - The throttler instance with control methods\n *\n * The throttled value will update according to the leading/trailing edge behavior specified in the options.\n *\n * For more direct control over throttling behavior without Solid state management,\n * consider using the lower-level createThrottler hook instead.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management via the underlying throttler instance.\n * The `selector` parameter allows you to specify which throttler 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 throttler state properties:\n * - `canLeadingExecute`: Whether the throttler can execute on the leading edge\n * - `canTrailingExecute`: Whether the throttler can execute on the trailing edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the throttler is waiting for the timeout to trigger trailing execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastExecutionTime`: Unix timestamp of the last execution\n * - `nextExecutionTime`: Unix timestamp of the next allowed execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [throttledValue, throttler] = createThrottledValue(rawValue, { wait: 1000 });\n *\n * // Opt-in to reactive updates when pending state changes (optimized for loading indicators)\n * const [throttledValue, throttler] = createThrottledValue(\n * rawValue,\n * { wait: 1000 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Use the throttled value\n * console.log(throttledValue()); // Access the current throttled value\n *\n * // Access throttler state via signals\n * console.log('Is pending:', throttler.state().isPending);\n *\n * // Control the throttler\n * throttler.cancel(); // Cancel any pending updates\n * ```\n */\nexport function createThrottledValue<TValue, TSelected = {}>(\n value: Accessor<TValue>,\n initialOptions: ThrottlerOptions<Setter<TValue>>,\n selector?: (state: ThrottlerState<Setter<TValue>>) => TSelected,\n): [Accessor<TValue>, SolidThrottler<Setter<TValue>, TSelected>] {\n const [throttledValue, setThrottledValue, throttler] = createThrottledSignal(\n value(),\n initialOptions,\n selector,\n )\n\n createEffect(() => {\n setThrottledValue(value() as any)\n })\n\n return [throttledValue, throttler]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,SAAgB,qBACd,OACA,gBACA,UAC+D;CAC/D,MAAM,CAAC,gBAAgB,mBAAmB,aAAa,sBACrD,OAAO,EACP,gBACA,SACD;AAED,oBAAmB;AACjB,oBAAkB,OAAO,CAAQ;GACjC;AAEF,QAAO,CAAC,gBAAgB,UAAU"}
@@ -1,7 +1,7 @@
1
1
  const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
2
  let solid_js = require("solid-js");
3
- let __tanstack_solid_store = require("@tanstack/solid-store");
4
- let __tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
3
+ let _tanstack_solid_store = require("@tanstack/solid-store");
4
+ let _tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
5
5
 
6
6
  //#region src/throttler/createThrottler.ts
7
7
  /**
@@ -17,14 +17,24 @@ let __tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
17
17
  *
18
18
  * ## State Management and Selector
19
19
  *
20
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
21
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
22
- * unnecessary re-renders when irrelevant state changes occur.
20
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
21
+ * in two ways:
22
+ *
23
+ * **1. Using `throttler.Subscribe` component (Recommended for component tree subscriptions)**
24
+ *
25
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
26
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
27
+ * in child components.
28
+ *
29
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
30
+ *
31
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
32
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
33
+ * state changes occur.
23
34
  *
24
35
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
25
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
26
- * full control over when your component updates. Only when you provide a selector will the
27
- * component re-render when the selected state values change.
36
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
37
+ * updates and gives you full control over when your component tracks state changes.
28
38
  *
29
39
  * Available state properties:
30
40
  * - `canLeadingExecute`: Whether the throttler can execute on the leading edge
@@ -41,21 +51,28 @@ let __tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
41
51
  * // Default behavior - no reactive state subscriptions
42
52
  * const throttler = createThrottler(setValue, { wait: 1000 });
43
53
  *
44
- * // Opt-in to re-render when isPending changes (optimized for loading states)
54
+ * // Subscribe to state changes deep in component tree using Subscribe component
55
+ * <throttler.Subscribe selector={(state) => ({ isPending: state.isPending })}>
56
+ * {(state) => (
57
+ * <div>{state().isPending ? 'Loading...' : 'Ready'}</div>
58
+ * )}
59
+ * </throttler.Subscribe>
60
+ *
61
+ * // Opt-in to track isPending changes at hook level (optimized for loading states)
45
62
  * const throttler = createThrottler(
46
63
  * setValue,
47
64
  * { wait: 1000 },
48
65
  * (state) => ({ isPending: state.isPending })
49
66
  * );
50
67
  *
51
- * // Opt-in to re-render when executionCount changes (optimized for tracking execution)
68
+ * // Opt-in to track executionCount changes (optimized for tracking execution)
52
69
  * const throttler = createThrottler(
53
70
  * setValue,
54
71
  * { wait: 1000 },
55
72
  * (state) => ({ executionCount: state.executionCount })
56
73
  * );
57
74
  *
58
- * // Multiple state properties - re-render when any of these change
75
+ * // Multiple state properties - track when any of these change
59
76
  * const throttler = createThrottler(
60
77
  * setValue,
61
78
  * {
@@ -76,11 +93,15 @@ let __tanstack_pacer_throttler = require("@tanstack/pacer/throttler");
76
93
  * ```
77
94
  */
78
95
  function createThrottler(fn, options, selector = () => ({})) {
79
- const asyncThrottler = new __tanstack_pacer_throttler.Throttler(fn, {
96
+ const asyncThrottler = new _tanstack_pacer_throttler.Throttler(fn, {
80
97
  ...require_PacerProvider.useDefaultPacerOptions().throttler,
81
98
  ...options
82
99
  });
83
- const state = (0, __tanstack_solid_store.useStore)(asyncThrottler.store, selector);
100
+ asyncThrottler.Subscribe = function Subscribe(props) {
101
+ const selected = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, props.selector);
102
+ return typeof props.children === "function" ? props.children(selected) : props.children;
103
+ };
104
+ const state = (0, _tanstack_solid_store.useStore)(asyncThrottler.store, selector);
84
105
  (0, solid_js.createEffect)(() => {
85
106
  (0, solid_js.onCleanup)(() => {
86
107
  asyncThrottler.cancel();