@tanstack/solid-pacer 0.15.3 → 0.16.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 (105) hide show
  1. package/README.md +165 -0
  2. package/dist/cjs/async-batcher/createAsyncBatcher.cjs +7 -2
  3. package/dist/cjs/async-batcher/createAsyncBatcher.cjs.map +1 -1
  4. package/dist/cjs/async-batcher/createAsyncBatcher.d.cts +1 -1
  5. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs +7 -2
  6. package/dist/cjs/async-debouncer/createAsyncDebouncer.cjs.map +1 -1
  7. package/dist/cjs/async-debouncer/createAsyncDebouncer.d.cts +1 -1
  8. package/dist/cjs/async-queuer/createAsyncQueuer.cjs +7 -2
  9. package/dist/cjs/async-queuer/createAsyncQueuer.cjs.map +1 -1
  10. package/dist/cjs/async-queuer/createAsyncQueuer.d.cts +1 -1
  11. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs +7 -2
  12. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.cjs.map +1 -1
  13. package/dist/cjs/async-rate-limiter/createAsyncRateLimiter.d.cts +1 -1
  14. package/dist/cjs/async-throttler/createAsyncThrottler.cjs +7 -2
  15. package/dist/cjs/async-throttler/createAsyncThrottler.cjs.map +1 -1
  16. package/dist/cjs/async-throttler/createAsyncThrottler.d.cts +1 -1
  17. package/dist/cjs/batcher/createBatcher.cjs +7 -2
  18. package/dist/cjs/batcher/createBatcher.cjs.map +1 -1
  19. package/dist/cjs/batcher/createBatcher.d.cts +1 -1
  20. package/dist/cjs/debouncer/createDebouncer.cjs +7 -2
  21. package/dist/cjs/debouncer/createDebouncer.cjs.map +1 -1
  22. package/dist/cjs/debouncer/createDebouncer.d.cts +1 -1
  23. package/dist/cjs/index.cjs +6 -0
  24. package/dist/cjs/index.cjs.map +1 -1
  25. package/dist/cjs/index.d.cts +2 -0
  26. package/dist/cjs/provider/PacerProvider.cjs +28 -0
  27. package/dist/cjs/provider/PacerProvider.cjs.map +1 -0
  28. package/dist/cjs/provider/PacerProvider.d.cts +25 -0
  29. package/dist/cjs/queuer/createQueuedSignal.cjs +9 -0
  30. package/dist/cjs/queuer/createQueuedSignal.cjs.map +1 -0
  31. package/dist/cjs/queuer/createQueuedSignal.d.cts +121 -0
  32. package/dist/cjs/queuer/createQueuer.cjs +7 -2
  33. package/dist/cjs/queuer/createQueuer.cjs.map +1 -1
  34. package/dist/cjs/queuer/createQueuer.d.cts +1 -1
  35. package/dist/cjs/queuer/index.cjs +2 -0
  36. package/dist/cjs/queuer/index.cjs.map +1 -1
  37. package/dist/cjs/queuer/index.d.cts +1 -0
  38. package/dist/cjs/rate-limiter/createRateLimitedValue.cjs.map +1 -1
  39. package/dist/cjs/rate-limiter/createRateLimitedValue.d.cts +30 -16
  40. package/dist/cjs/rate-limiter/createRateLimiter.cjs +7 -2
  41. package/dist/cjs/rate-limiter/createRateLimiter.cjs.map +1 -1
  42. package/dist/cjs/rate-limiter/createRateLimiter.d.cts +1 -1
  43. package/dist/cjs/throttler/createThrottler.cjs +7 -2
  44. package/dist/cjs/throttler/createThrottler.cjs.map +1 -1
  45. package/dist/cjs/throttler/createThrottler.d.cts +1 -1
  46. package/dist/esm/async-batcher/createAsyncBatcher.d.ts +1 -1
  47. package/dist/esm/async-batcher/createAsyncBatcher.js +7 -2
  48. package/dist/esm/async-batcher/createAsyncBatcher.js.map +1 -1
  49. package/dist/esm/async-debouncer/createAsyncDebouncer.d.ts +1 -1
  50. package/dist/esm/async-debouncer/createAsyncDebouncer.js +7 -2
  51. package/dist/esm/async-debouncer/createAsyncDebouncer.js.map +1 -1
  52. package/dist/esm/async-queuer/createAsyncQueuer.d.ts +1 -1
  53. package/dist/esm/async-queuer/createAsyncQueuer.js +7 -2
  54. package/dist/esm/async-queuer/createAsyncQueuer.js.map +1 -1
  55. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.d.ts +1 -1
  56. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js +7 -2
  57. package/dist/esm/async-rate-limiter/createAsyncRateLimiter.js.map +1 -1
  58. package/dist/esm/async-throttler/createAsyncThrottler.d.ts +1 -1
  59. package/dist/esm/async-throttler/createAsyncThrottler.js +7 -2
  60. package/dist/esm/async-throttler/createAsyncThrottler.js.map +1 -1
  61. package/dist/esm/batcher/createBatcher.d.ts +1 -1
  62. package/dist/esm/batcher/createBatcher.js +7 -2
  63. package/dist/esm/batcher/createBatcher.js.map +1 -1
  64. package/dist/esm/debouncer/createDebouncer.d.ts +1 -1
  65. package/dist/esm/debouncer/createDebouncer.js +7 -2
  66. package/dist/esm/debouncer/createDebouncer.js.map +1 -1
  67. package/dist/esm/index.d.ts +2 -0
  68. package/dist/esm/index.js +7 -1
  69. package/dist/esm/index.js.map +1 -1
  70. package/dist/esm/provider/PacerProvider.d.ts +25 -0
  71. package/dist/esm/provider/PacerProvider.js +28 -0
  72. package/dist/esm/provider/PacerProvider.js.map +1 -0
  73. package/dist/esm/queuer/createQueuedSignal.d.ts +121 -0
  74. package/dist/esm/queuer/createQueuedSignal.js +9 -0
  75. package/dist/esm/queuer/createQueuedSignal.js.map +1 -0
  76. package/dist/esm/queuer/createQueuer.d.ts +1 -1
  77. package/dist/esm/queuer/createQueuer.js +7 -2
  78. package/dist/esm/queuer/createQueuer.js.map +1 -1
  79. package/dist/esm/queuer/index.d.ts +1 -0
  80. package/dist/esm/queuer/index.js +2 -0
  81. package/dist/esm/queuer/index.js.map +1 -1
  82. package/dist/esm/rate-limiter/createRateLimitedValue.d.ts +30 -16
  83. package/dist/esm/rate-limiter/createRateLimitedValue.js.map +1 -1
  84. package/dist/esm/rate-limiter/createRateLimiter.d.ts +1 -1
  85. package/dist/esm/rate-limiter/createRateLimiter.js +7 -2
  86. package/dist/esm/rate-limiter/createRateLimiter.js.map +1 -1
  87. package/dist/esm/throttler/createThrottler.d.ts +1 -1
  88. package/dist/esm/throttler/createThrottler.js +7 -2
  89. package/dist/esm/throttler/createThrottler.js.map +1 -1
  90. package/package.json +1 -1
  91. package/src/async-batcher/createAsyncBatcher.ts +8 -2
  92. package/src/async-debouncer/createAsyncDebouncer.ts +8 -2
  93. package/src/async-queuer/createAsyncQueuer.ts +8 -2
  94. package/src/async-rate-limiter/createAsyncRateLimiter.ts +8 -2
  95. package/src/async-throttler/createAsyncThrottler.ts +8 -2
  96. package/src/batcher/createBatcher.ts +8 -2
  97. package/src/debouncer/createDebouncer.ts +8 -2
  98. package/src/index.ts +4 -0
  99. package/src/provider/PacerProvider.tsx +63 -0
  100. package/src/queuer/createQueuedSignal.ts +138 -0
  101. package/src/queuer/createQueuer.ts +8 -2
  102. package/src/queuer/index.ts +1 -0
  103. package/src/rate-limiter/createRateLimitedValue.ts +30 -16
  104. package/src/rate-limiter/createRateLimiter.ts +8 -2
  105. package/src/throttler/createThrottler.ts +8 -2
@@ -1,6 +1,7 @@
1
1
  import { Debouncer } from '@tanstack/pacer/debouncer'
2
2
  import { createEffect, onCleanup } from 'solid-js'
3
3
  import { useStore } from '@tanstack/solid-store'
4
+ import { useDefaultPacerOptions } from '../provider/PacerProvider'
4
5
  import type { Store } from '@tanstack/solid-store'
5
6
  import type { Accessor } from 'solid-js'
6
7
  import type { AnyFunction } from '@tanstack/pacer/types'
@@ -102,10 +103,15 @@ export interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}>
102
103
  */
103
104
  export function createDebouncer<TFn extends AnyFunction, TSelected = {}>(
104
105
  fn: TFn,
105
- initialOptions: DebouncerOptions<TFn>,
106
+ options: DebouncerOptions<TFn>,
106
107
  selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,
107
108
  ): SolidDebouncer<TFn, TSelected> {
108
- const asyncDebouncer = new Debouncer<TFn>(fn, initialOptions)
109
+ const mergedOptions = {
110
+ ...useDefaultPacerOptions().debouncer,
111
+ ...options,
112
+ } as DebouncerOptions<TFn>
113
+
114
+ const asyncDebouncer = new Debouncer<TFn>(fn, mergedOptions)
109
115
 
110
116
  const state = useStore(asyncDebouncer.store, selector)
111
117
 
package/src/index.ts CHANGED
@@ -1,6 +1,9 @@
1
1
  // re-export everything from the core pacer package
2
2
  export * from '@tanstack/pacer'
3
3
 
4
+ // provider
5
+ export * from './provider/PacerProvider'
6
+
4
7
  /**
5
8
  * Export every hook individually - DON'T export from barrel files
6
9
  */
@@ -30,6 +33,7 @@ export * from './debouncer/createDebouncer'
30
33
 
31
34
  // queuer
32
35
  export * from './queuer/createQueuer'
36
+ export * from './queuer/createQueuedSignal'
33
37
 
34
38
  // rate-limiter
35
39
  export * from './rate-limiter/createRateLimiter'
@@ -0,0 +1,63 @@
1
+ import { createContext, useContext } from 'solid-js'
2
+ import type { JSX } from 'solid-js'
3
+ import type {
4
+ AnyAsyncFunction,
5
+ AnyFunction,
6
+ AsyncBatcherOptions,
7
+ AsyncDebouncerOptions,
8
+ AsyncQueuerOptions,
9
+ AsyncRateLimiterOptions,
10
+ AsyncThrottlerOptions,
11
+ BatcherOptions,
12
+ DebouncerOptions,
13
+ QueuerOptions,
14
+ RateLimiterOptions,
15
+ ThrottlerOptions,
16
+ } from '@tanstack/pacer'
17
+
18
+ export interface PacerProviderOptions {
19
+ asyncBatcher?: Partial<AsyncBatcherOptions<any>>
20
+ asyncDebouncer?: Partial<AsyncDebouncerOptions<AnyAsyncFunction>>
21
+ asyncQueuer?: Partial<AsyncQueuerOptions<any>>
22
+ asyncRateLimiter?: Partial<AsyncRateLimiterOptions<AnyAsyncFunction>>
23
+ asyncThrottler?: Partial<AsyncThrottlerOptions<AnyAsyncFunction>>
24
+ batcher?: Partial<BatcherOptions<any>>
25
+ debouncer?: Partial<DebouncerOptions<AnyFunction>>
26
+ queuer?: Partial<QueuerOptions<any>>
27
+ rateLimiter?: Partial<RateLimiterOptions<AnyFunction>>
28
+ throttler?: Partial<ThrottlerOptions<AnyFunction>>
29
+ }
30
+
31
+ interface PacerContextValue {
32
+ defaultOptions: PacerProviderOptions
33
+ }
34
+
35
+ const PacerContext = createContext<PacerContextValue | null>(null)
36
+
37
+ export interface PacerProviderProps {
38
+ children: JSX.Element
39
+ defaultOptions?: PacerProviderOptions
40
+ }
41
+
42
+ const DEFAULT_OPTIONS: PacerProviderOptions = {}
43
+
44
+ export function PacerProvider(props: PacerProviderProps) {
45
+ const contextValue: PacerContextValue = {
46
+ defaultOptions: props.defaultOptions ?? DEFAULT_OPTIONS,
47
+ }
48
+
49
+ return (
50
+ <PacerContext.Provider value={contextValue}>
51
+ {props.children}
52
+ </PacerContext.Provider>
53
+ )
54
+ }
55
+
56
+ export function usePacerContext() {
57
+ return useContext(PacerContext)
58
+ }
59
+
60
+ export function useDefaultPacerOptions() {
61
+ const context = useContext(PacerContext)
62
+ return context?.defaultOptions ?? {}
63
+ }
@@ -0,0 +1,138 @@
1
+ import { createQueuer } from './createQueuer'
2
+ import type { SolidQueuer } from './createQueuer'
3
+ import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
4
+
5
+ /**
6
+ * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.
7
+ * This primitive provides both the current queue state and queue control methods.
8
+ *
9
+ * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.
10
+ * All queue operations are reflected in the state array returned by the primitive.
11
+ *
12
+ * The queue can be started and stopped to automatically process items at a specified interval,
13
+ * making it useful as a scheduler. When started, it will process one item per tick, with an
14
+ * optional wait time between ticks.
15
+ *
16
+ * The primitive returns a tuple containing:
17
+ * - The current queue state as an array
18
+ * - The queue instance with methods for queue manipulation
19
+ *
20
+ * ## State Management and Selector
21
+ *
22
+ * The primitive uses Solid's reactive state management via the underlying queuer instance.
23
+ * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
24
+ * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
25
+ *
26
+ * **By default, there will be no reactive state subscriptions** and you must opt-in to state
27
+ * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
28
+ * full control over when your component updates. Only when you provide a selector will the
29
+ * component re-render when the selected state values change.
30
+ *
31
+ * Available queuer state properties:
32
+ * - `executionCount`: Number of items that have been processed by the queuer
33
+ * - `expirationCount`: Number of items that have been removed due to expiration
34
+ * - `isEmpty`: Whether the queuer has no items to process
35
+ * - `isFull`: Whether the queuer has reached its maximum capacity
36
+ * - `isIdle`: Whether the queuer is not currently processing any items
37
+ * - `isRunning`: Whether the queuer is active and will process items automatically
38
+ * - `items`: Array of items currently waiting to be processed
39
+ * - `itemTimestamps`: Timestamps when items were added for expiration tracking
40
+ * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item
41
+ * - `rejectionCount`: Number of items that have been rejected from being added
42
+ * - `size`: Number of items currently in the queue
43
+ * - `status`: Current processing status ('idle' | 'running' | 'stopped')
44
+ *
45
+ * @example
46
+ * ```tsx
47
+ * // Default behavior - no reactive state subscriptions
48
+ * const [items, addItem, queue] = createQueuedSignal(
49
+ * (item) => console.log('Processing:', item),
50
+ * {
51
+ * initialItems: ['item1', 'item2'],
52
+ * started: true,
53
+ * wait: 1000,
54
+ * getPriority: (item) => item.priority
55
+ * }
56
+ * );
57
+ *
58
+ * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
59
+ * const [items, addItem, queue] = createQueuedSignal(
60
+ * (item) => console.log('Processing:', item),
61
+ * { started: true, wait: 1000 },
62
+ * (state) => ({
63
+ * items: state.items,
64
+ * size: state.size,
65
+ * isEmpty: state.isEmpty
66
+ * })
67
+ * );
68
+ *
69
+ * // Opt-in to re-render when processing state changes (optimized for loading indicators)
70
+ * const [items, addItem, queue] = createQueuedSignal(
71
+ * (item) => console.log('Processing:', item),
72
+ * { started: true, wait: 1000 },
73
+ * (state) => ({
74
+ * isRunning: state.isRunning,
75
+ * isIdle: state.isIdle,
76
+ * status: state.status,
77
+ * pendingTick: state.pendingTick
78
+ * })
79
+ * );
80
+ *
81
+ * // Opt-in to re-render when execution metrics change (optimized for stats display)
82
+ * const [items, addItem, queue] = createQueuedSignal(
83
+ * (item) => console.log('Processing:', item),
84
+ * { started: true, wait: 1000 },
85
+ * (state) => ({
86
+ * executionCount: state.executionCount,
87
+ * expirationCount: state.expirationCount,
88
+ * rejectionCount: state.rejectionCount
89
+ * })
90
+ * );
91
+ *
92
+ * // Add items to queue
93
+ * const handleAdd = (item) => {
94
+ * addItem(item);
95
+ * };
96
+ *
97
+ * // Start automatic processing
98
+ * const startProcessing = () => {
99
+ * queue.start();
100
+ * };
101
+ *
102
+ * // Stop automatic processing
103
+ * const stopProcessing = () => {
104
+ * queue.stop();
105
+ * };
106
+ *
107
+ * // Manual processing still available
108
+ * const handleProcess = () => {
109
+ * const nextItem = queue.getNextItem();
110
+ * if (nextItem) {
111
+ * processItem(nextItem);
112
+ * }
113
+ * };
114
+ *
115
+ * // Access the selected queuer state (will be empty object {} unless selector provided)
116
+ * const { size, isRunning, executionCount } = queue.state;
117
+ * ```
118
+ */
119
+ export function createQueuedSignal<
120
+ TValue,
121
+ TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
122
+ QueuerState<TValue>,
123
+ 'items'
124
+ >,
125
+ >(
126
+ fn: (item: TValue) => void,
127
+ options: QueuerOptions<TValue> = {},
128
+ selector: (state: QueuerState<TValue>) => TSelected = (state) =>
129
+ ({ items: state.items }) as TSelected,
130
+ ): [
131
+ () => Array<TValue>,
132
+ SolidQueuer<TValue, TSelected>['addItem'],
133
+ SolidQueuer<TValue, TSelected>,
134
+ ] {
135
+ const queue = createQueuer(fn, options, selector)
136
+
137
+ return [() => queue.state().items, queue.addItem, queue]
138
+ }
@@ -1,5 +1,6 @@
1
1
  import { Queuer } from '@tanstack/pacer/queuer'
2
2
  import { useStore } from '@tanstack/solid-store'
3
+ import { useDefaultPacerOptions } from '../provider/PacerProvider'
3
4
  import type { Store } from '@tanstack/solid-store'
4
5
  import type { Accessor } from 'solid-js'
5
6
  import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
@@ -100,10 +101,15 @@ export interface SolidQueuer<TValue, TSelected = {}>
100
101
  */
101
102
  export function createQueuer<TValue, TSelected = {}>(
102
103
  fn: (item: TValue) => void,
103
- initialOptions: QueuerOptions<TValue> = {},
104
+ options: QueuerOptions<TValue> = {},
104
105
  selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,
105
106
  ): SolidQueuer<TValue, TSelected> {
106
- const queuer = new Queuer(fn, initialOptions)
107
+ const mergedOptions = {
108
+ ...useDefaultPacerOptions().queuer,
109
+ ...options,
110
+ } as QueuerOptions<TValue>
111
+
112
+ const queuer = new Queuer(fn, mergedOptions)
107
113
 
108
114
  const state = useStore(queuer.store, selector)
109
115
 
@@ -1,3 +1,4 @@
1
1
  export * from '@tanstack/pacer/queuer'
2
2
 
3
3
  export * from './createQueuer'
4
+ export * from './createQueuedSignal'
@@ -46,13 +46,9 @@ import type {
46
46
  * the reactive system track the selected state values.
47
47
  *
48
48
  * Available rate limiter state properties:
49
- * - `callsInWindow`: Number of calls made in the current window
50
- * - `remainingInWindow`: Number of calls remaining in the current window
51
- * - `windowStart`: Unix timestamp when the current window started
52
- * - `nextWindowStart`: Unix timestamp when the next window will start
53
- * - `msUntilNextWindow`: Milliseconds until the next window starts
54
- * - `isAtLimit`: Whether the call limit for the current window has been reached
55
- * - `status`: Current status ('disabled' | 'idle' | 'at-limit')
49
+ * - `executionCount`: Number of function executions that have been completed
50
+ * - `executionTimes`: Array of timestamps when executions occurred for rate limiting calculations
51
+ * - `rejectionCount`: Number of function executions that have been rejected due to rate limiting
56
52
  *
57
53
  * @example
58
54
  * ```tsx
@@ -63,21 +59,39 @@ import type {
63
59
  * windowType: 'sliding'
64
60
  * });
65
61
  *
66
- * // Opt-in to reactive updates when limit state changes (optimized for UI feedback)
62
+ * // Opt-in to reactive updates when execution count changes (optimized for tracking successful updates)
67
63
  * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
68
64
  * rawValue,
69
- * { limit: 5, window: 60000 },
70
- * (state) => ({ isAtLimit: state.isAtLimit, remainingInWindow: state.remainingInWindow })
65
+ * { limit: 5, window: 60000, windowType: 'sliding' },
66
+ * (state) => ({ executionCount: state.executionCount })
71
67
  * );
72
68
  *
73
- * // Use the rate-limited value
74
- * console.log(rateLimitedValue()); // Access the current rate-limited value
69
+ * // Opt-in to reactive updates when rejection count changes (optimized for tracking rate limit violations)
70
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
71
+ * rawValue,
72
+ * { limit: 5, window: 60000, windowType: 'sliding' },
73
+ * (state) => ({ rejectionCount: state.rejectionCount })
74
+ * );
75
75
  *
76
- * // Access rate limiter state via signals
77
- * console.log('Is at limit:', rateLimiter.state().isAtLimit);
76
+ * // Opt-in to reactive updates when execution times change (optimized for window calculations)
77
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(
78
+ * rawValue,
79
+ * { limit: 5, window: 60000, windowType: 'sliding' },
80
+ * (state) => ({ executionTimes: state.executionTimes })
81
+ * );
82
+ *
83
+ * // With rejection callback and fixed window
84
+ * const [rateLimitedValue, rateLimiter] = createRateLimitedValue(rawValue, {
85
+ * limit: 3,
86
+ * window: 5000,
87
+ * windowType: 'fixed',
88
+ * onReject: (rateLimiter) => {
89
+ * console.log(`Update rejected. Try again in ${rateLimiter.getMsUntilNextWindow()}ms`);
90
+ * }
91
+ * });
78
92
  *
79
- * // Control the rate limiter
80
- * rateLimiter.reset(); // Reset the rate limit window
93
+ * // Access the selected rate limiter state (will be empty object {} unless selector provided)
94
+ * const { executionCount, rejectionCount } = rateLimiter.state;
81
95
  * ```
82
96
  */
83
97
  export function createRateLimitedValue<TValue, TSelected = {}>(
@@ -1,5 +1,6 @@
1
1
  import { RateLimiter } from '@tanstack/pacer/rate-limiter'
2
2
  import { useStore } from '@tanstack/solid-store'
3
+ import { useDefaultPacerOptions } from '../provider/PacerProvider'
3
4
  import type { Store } from '@tanstack/solid-store'
4
5
  import type { Accessor } from 'solid-js'
5
6
  import type { AnyFunction } from '@tanstack/pacer/types'
@@ -101,10 +102,15 @@ export interface SolidRateLimiter<TFn extends AnyFunction, TSelected = {}>
101
102
  */
102
103
  export function createRateLimiter<TFn extends AnyFunction, TSelected = {}>(
103
104
  fn: TFn,
104
- initialOptions: RateLimiterOptions<TFn>,
105
+ options: RateLimiterOptions<TFn>,
105
106
  selector: (state: RateLimiterState) => TSelected = () => ({}) as TSelected,
106
107
  ): SolidRateLimiter<TFn, TSelected> {
107
- const rateLimiter = new RateLimiter<TFn>(fn, initialOptions)
108
+ const mergedOptions = {
109
+ ...useDefaultPacerOptions().rateLimiter,
110
+ ...options,
111
+ } as RateLimiterOptions<TFn>
112
+
113
+ const rateLimiter = new RateLimiter<TFn>(fn, mergedOptions)
108
114
 
109
115
  const state = useStore(rateLimiter.store, selector)
110
116
 
@@ -1,6 +1,7 @@
1
1
  import { Throttler } from '@tanstack/pacer/throttler'
2
2
  import { createEffect, onCleanup } from 'solid-js'
3
3
  import { useStore } from '@tanstack/solid-store'
4
+ import { useDefaultPacerOptions } from '../provider/PacerProvider'
4
5
  import type { Store } from '@tanstack/solid-store'
5
6
  import type { Accessor } from 'solid-js'
6
7
  import type { AnyFunction } from '@tanstack/pacer/types'
@@ -98,10 +99,15 @@ export interface SolidThrottler<TFn extends AnyFunction, TSelected = {}>
98
99
  */
99
100
  export function createThrottler<TFn extends AnyFunction, TSelected = {}>(
100
101
  fn: TFn,
101
- initialOptions: ThrottlerOptions<TFn>,
102
+ options: ThrottlerOptions<TFn>,
102
103
  selector: (state: ThrottlerState<TFn>) => TSelected = () => ({}) as TSelected,
103
104
  ): SolidThrottler<TFn, TSelected> {
104
- const asyncThrottler = new Throttler<TFn>(fn, initialOptions)
105
+ const mergedOptions = {
106
+ ...useDefaultPacerOptions().throttler,
107
+ ...options,
108
+ } as ThrottlerOptions<TFn>
109
+
110
+ const asyncThrottler = new Throttler<TFn>(fn, mergedOptions)
105
111
 
106
112
  const state = useStore(asyncThrottler.store, selector)
107
113