@tanstack/pacer 0.16.0 → 0.16.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 (93) hide show
  1. package/dist/cjs/async-batcher.cjs +1 -2
  2. package/dist/cjs/async-batcher.cjs.map +1 -1
  3. package/dist/cjs/async-batcher.d.cts +1 -5
  4. package/dist/cjs/async-debouncer.cjs +1 -2
  5. package/dist/cjs/async-debouncer.cjs.map +1 -1
  6. package/dist/cjs/async-debouncer.d.cts +1 -5
  7. package/dist/cjs/async-queuer.cjs +1 -2
  8. package/dist/cjs/async-queuer.cjs.map +1 -1
  9. package/dist/cjs/async-queuer.d.cts +1 -5
  10. package/dist/cjs/async-rate-limiter.cjs +1 -2
  11. package/dist/cjs/async-rate-limiter.cjs.map +1 -1
  12. package/dist/cjs/async-rate-limiter.d.cts +1 -5
  13. package/dist/cjs/async-retryer.cjs +1 -2
  14. package/dist/cjs/async-retryer.cjs.map +1 -1
  15. package/dist/cjs/async-retryer.d.cts +1 -5
  16. package/dist/cjs/async-throttler.cjs +1 -2
  17. package/dist/cjs/async-throttler.cjs.map +1 -1
  18. package/dist/cjs/async-throttler.d.cts +1 -5
  19. package/dist/cjs/batcher.cjs +1 -2
  20. package/dist/cjs/batcher.cjs.map +1 -1
  21. package/dist/cjs/batcher.d.cts +1 -5
  22. package/dist/cjs/debouncer.cjs +1 -2
  23. package/dist/cjs/debouncer.cjs.map +1 -1
  24. package/dist/cjs/debouncer.d.cts +1 -5
  25. package/dist/cjs/event-client.cjs +3 -1
  26. package/dist/cjs/event-client.cjs.map +1 -1
  27. package/dist/cjs/index.cjs +0 -1
  28. package/dist/cjs/index.cjs.map +1 -1
  29. package/dist/cjs/queuer.cjs +1 -2
  30. package/dist/cjs/queuer.cjs.map +1 -1
  31. package/dist/cjs/queuer.d.cts +1 -5
  32. package/dist/cjs/rate-limiter.cjs +1 -2
  33. package/dist/cjs/rate-limiter.cjs.map +1 -1
  34. package/dist/cjs/rate-limiter.d.cts +1 -5
  35. package/dist/cjs/throttler.cjs +1 -2
  36. package/dist/cjs/throttler.cjs.map +1 -1
  37. package/dist/cjs/throttler.d.cts +0 -4
  38. package/dist/cjs/utils.cjs +0 -10
  39. package/dist/cjs/utils.cjs.map +1 -1
  40. package/dist/cjs/utils.d.cts +0 -1
  41. package/dist/esm/async-batcher.d.ts +1 -5
  42. package/dist/esm/async-batcher.js +2 -3
  43. package/dist/esm/async-batcher.js.map +1 -1
  44. package/dist/esm/async-debouncer.d.ts +1 -5
  45. package/dist/esm/async-debouncer.js +2 -3
  46. package/dist/esm/async-debouncer.js.map +1 -1
  47. package/dist/esm/async-queuer.d.ts +1 -5
  48. package/dist/esm/async-queuer.js +2 -3
  49. package/dist/esm/async-queuer.js.map +1 -1
  50. package/dist/esm/async-rate-limiter.d.ts +1 -5
  51. package/dist/esm/async-rate-limiter.js +2 -3
  52. package/dist/esm/async-rate-limiter.js.map +1 -1
  53. package/dist/esm/async-retryer.d.ts +1 -5
  54. package/dist/esm/async-retryer.js +2 -3
  55. package/dist/esm/async-retryer.js.map +1 -1
  56. package/dist/esm/async-throttler.d.ts +1 -5
  57. package/dist/esm/async-throttler.js +2 -3
  58. package/dist/esm/async-throttler.js.map +1 -1
  59. package/dist/esm/batcher.d.ts +1 -5
  60. package/dist/esm/batcher.js +2 -3
  61. package/dist/esm/batcher.js.map +1 -1
  62. package/dist/esm/debouncer.d.ts +1 -5
  63. package/dist/esm/debouncer.js +2 -3
  64. package/dist/esm/debouncer.js.map +1 -1
  65. package/dist/esm/event-client.js +3 -1
  66. package/dist/esm/event-client.js.map +1 -1
  67. package/dist/esm/index.js +1 -2
  68. package/dist/esm/queuer.d.ts +1 -5
  69. package/dist/esm/queuer.js +2 -3
  70. package/dist/esm/queuer.js.map +1 -1
  71. package/dist/esm/rate-limiter.d.ts +1 -5
  72. package/dist/esm/rate-limiter.js +2 -3
  73. package/dist/esm/rate-limiter.js.map +1 -1
  74. package/dist/esm/throttler.d.ts +0 -4
  75. package/dist/esm/throttler.js +2 -3
  76. package/dist/esm/throttler.js.map +1 -1
  77. package/dist/esm/utils.d.ts +0 -1
  78. package/dist/esm/utils.js +0 -10
  79. package/dist/esm/utils.js.map +1 -1
  80. package/package.json +3 -3
  81. package/src/async-batcher.ts +3 -8
  82. package/src/async-debouncer.ts +3 -8
  83. package/src/async-queuer.ts +3 -8
  84. package/src/async-rate-limiter.ts +3 -8
  85. package/src/async-retryer.ts +3 -8
  86. package/src/async-throttler.ts +3 -8
  87. package/src/batcher.ts +3 -8
  88. package/src/debouncer.ts +3 -8
  89. package/src/event-client.ts +3 -1
  90. package/src/queuer.ts +3 -8
  91. package/src/rate-limiter.ts +3 -8
  92. package/src/throttler.ts +2 -7
  93. package/src/utils.ts +0 -15
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
  import type { AnyAsyncFunction } from './types'
5
5
 
@@ -289,7 +289,7 @@ export class AsyncRetryer<TFn extends AnyAsyncFunction> {
289
289
  readonly store: Store<Readonly<AsyncRetryerState<TFn>>> = new Store(
290
290
  getDefaultAsyncRetryerState<TFn>(),
291
291
  )
292
- key: string
292
+ key: string | undefined
293
293
  options: AsyncRetryerOptions<TFn> & typeof defaultOptions
294
294
  #abortController: AbortController | null = null
295
295
 
@@ -302,7 +302,7 @@ export class AsyncRetryer<TFn extends AnyAsyncFunction> {
302
302
  public fn: TFn,
303
303
  initialOptions: AsyncRetryerOptions<TFn> = {},
304
304
  ) {
305
- this.key = createKey(initialOptions.key)
305
+ this.key = initialOptions.key
306
306
  this.options = {
307
307
  ...defaultOptions,
308
308
  ...initialOptions,
@@ -319,11 +319,6 @@ export class AsyncRetryer<TFn extends AnyAsyncFunction> {
319
319
  })
320
320
  }
321
321
 
322
- /**
323
- * Emits a change event for the async retryer instance. Mostly useful for devtools.
324
- */
325
- _emit = () => emitChange('AsyncRetryer', this)
326
-
327
322
  /**
328
323
  * Updates the retryer options
329
324
  * @param newOptions Partial options to merge with existing options
@@ -1,6 +1,6 @@
1
1
  import { Store } from '@tanstack/store'
2
2
  import { AsyncRetryer } from './async-retryer'
3
- import { createKey, parseFunctionOrValue } from './utils'
3
+ import { parseFunctionOrValue } from './utils'
4
4
  import { emitChange, pacerEventClient } from './event-client'
5
5
  import type { AsyncRetryerOptions } from './async-retryer'
6
6
  import type { AnyAsyncFunction, OptionalKeys } from './types'
@@ -231,7 +231,7 @@ export class AsyncThrottler<TFn extends AnyAsyncFunction> {
231
231
  readonly store: Store<Readonly<AsyncThrottlerState<TFn>>> = new Store<
232
232
  AsyncThrottlerState<TFn>
233
233
  >(getDefaultAsyncThrottlerState<TFn>())
234
- key: string
234
+ key: string | undefined
235
235
  options: AsyncThrottlerOptions<TFn>
236
236
  asyncRetryers = new Map<number, AsyncRetryer<TFn>>()
237
237
  #timeoutId: NodeJS.Timeout | null = null
@@ -243,7 +243,7 @@ export class AsyncThrottler<TFn extends AnyAsyncFunction> {
243
243
  public fn: TFn,
244
244
  initialOptions: AsyncThrottlerOptions<TFn>,
245
245
  ) {
246
- this.key = createKey(initialOptions.key)
246
+ this.key = initialOptions.key
247
247
  this.options = {
248
248
  ...defaultOptions,
249
249
  ...initialOptions,
@@ -258,11 +258,6 @@ export class AsyncThrottler<TFn extends AnyAsyncFunction> {
258
258
  })
259
259
  }
260
260
 
261
- /**
262
- * Emits a change event for the async throttler instance. Mostly useful for devtools.
263
- */
264
- _emit = () => emitChange('AsyncThrottler', this)
265
-
266
261
  /**
267
262
  * Updates the async throttler options
268
263
  */
package/src/batcher.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
  import type { OptionalKeys } from './types'
5
5
 
@@ -146,7 +146,7 @@ export class Batcher<TValue> {
146
146
  readonly store: Store<Readonly<BatcherState<TValue>>> = new Store(
147
147
  getDefaultBatcherState<TValue>(),
148
148
  )
149
- key: string
149
+ key: string | undefined
150
150
  options: BatcherOptionsWithOptionalCallbacks<TValue>
151
151
  #timeoutId: NodeJS.Timeout | null = null
152
152
 
@@ -154,7 +154,7 @@ export class Batcher<TValue> {
154
154
  public fn: (items: Array<TValue>) => void,
155
155
  initialOptions: BatcherOptions<TValue>,
156
156
  ) {
157
- this.key = createKey(initialOptions.key)
157
+ this.key = initialOptions.key
158
158
  this.options = {
159
159
  ...defaultOptions,
160
160
  ...initialOptions,
@@ -168,11 +168,6 @@ export class Batcher<TValue> {
168
168
  })
169
169
  }
170
170
 
171
- /**
172
- * Emits a change event for the batcher instance. Mostly useful for devtools.
173
- */
174
- _emit = () => emitChange('Batcher', this)
175
-
176
171
  /**
177
172
  * Updates the batcher options
178
173
  */
package/src/debouncer.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
  import type { AnyFunction } from './types'
5
5
 
@@ -143,7 +143,7 @@ export class Debouncer<TFn extends AnyFunction> {
143
143
  readonly store: Store<Readonly<DebouncerState<TFn>>> = new Store(
144
144
  getDefaultDebouncerState<TFn>(),
145
145
  )
146
- key: string
146
+ key: string | undefined
147
147
  options: DebouncerOptions<TFn>
148
148
  #timeoutId: NodeJS.Timeout | undefined
149
149
 
@@ -151,7 +151,7 @@ export class Debouncer<TFn extends AnyFunction> {
151
151
  public fn: TFn,
152
152
  initialOptions: DebouncerOptions<TFn>,
153
153
  ) {
154
- this.key = createKey(initialOptions.key)
154
+ this.key = initialOptions.key
155
155
  this.options = {
156
156
  ...defaultOptions,
157
157
  ...initialOptions,
@@ -165,11 +165,6 @@ export class Debouncer<TFn extends AnyFunction> {
165
165
  })
166
166
  }
167
167
 
168
- /**
169
- * Emits a change event for the debouncer instance. Mostly useful for devtools.
170
- */
171
- _emit = () => emitChange('Debouncer', this)
172
-
173
168
  /**
174
169
  * Updates the debouncer options
175
170
  */
@@ -60,7 +60,9 @@ export const emitChange = <
60
60
  event: TSuffix,
61
61
  payload: PacerEventMap[`pacer:${TSuffix}`],
62
62
  ) => {
63
- pacerEventClient.emit(event, payload)
63
+ if (payload.key) {
64
+ pacerEventClient.emit(event, payload)
65
+ }
64
66
  }
65
67
 
66
68
  export const pacerEventClient = new PacerEventClient()
package/src/queuer.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
 
5
5
  export interface QueuerState<TValue> {
@@ -270,7 +270,7 @@ export class Queuer<TValue> {
270
270
  readonly store: Store<Readonly<QueuerState<TValue>>> = new Store(
271
271
  getDefaultQueuerState<TValue>(),
272
272
  )
273
- key: string
273
+ key: string | undefined
274
274
  options: QueuerOptions<TValue>
275
275
  #timeoutId: NodeJS.Timeout | null = null
276
276
 
@@ -278,7 +278,7 @@ export class Queuer<TValue> {
278
278
  public fn: (item: TValue) => void,
279
279
  initialOptions: QueuerOptions<TValue> = {},
280
280
  ) {
281
- this.key = createKey(initialOptions.key)
281
+ this.key = initialOptions.key
282
282
  this.options = {
283
283
  ...defaultOptions,
284
284
  ...initialOptions,
@@ -309,11 +309,6 @@ export class Queuer<TValue> {
309
309
  })
310
310
  }
311
311
 
312
- /**
313
- * Emits a change event for the queuer instance. Mostly useful for devtools.
314
- */
315
- _emit = () => emitChange('Queuer', this)
316
-
317
312
  /**
318
313
  * Updates the queuer options. New options are merged with existing options.
319
314
  */
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
  import type { AnyFunction } from './types'
5
5
 
@@ -156,7 +156,7 @@ const defaultOptions: Omit<
156
156
  export class RateLimiter<TFn extends AnyFunction> {
157
157
  readonly store: Store<Readonly<RateLimiterState>> =
158
158
  new Store<RateLimiterState>(getDefaultRateLimiterState())
159
- key: string
159
+ key: string | undefined
160
160
  options: RateLimiterOptions<TFn>
161
161
  #timeoutIds: Set<NodeJS.Timeout> = new Set()
162
162
 
@@ -164,7 +164,7 @@ export class RateLimiter<TFn extends AnyFunction> {
164
164
  public fn: TFn,
165
165
  initialOptions: RateLimiterOptions<TFn>,
166
166
  ) {
167
- this.key = createKey(initialOptions.key)
167
+ this.key = initialOptions.key
168
168
  this.options = {
169
169
  ...defaultOptions,
170
170
  ...initialOptions,
@@ -181,11 +181,6 @@ export class RateLimiter<TFn extends AnyFunction> {
181
181
  })
182
182
  }
183
183
 
184
- /**
185
- * Emits a change event for the rate limiter instance. Mostly useful for devtools.
186
- */
187
- _emit = () => emitChange('RateLimiter', this)
188
-
189
184
  /**
190
185
  * Updates the rate limiter options
191
186
  */
package/src/throttler.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Store } from '@tanstack/store'
2
- import { createKey, parseFunctionOrValue } from './utils'
2
+ import { parseFunctionOrValue } from './utils'
3
3
  import { emitChange, pacerEventClient } from './event-client'
4
4
  import type { AnyFunction } from './types'
5
5
 
@@ -159,7 +159,7 @@ export class Throttler<TFn extends AnyFunction> {
159
159
  public fn: TFn,
160
160
  initialOptions: ThrottlerOptions<TFn>,
161
161
  ) {
162
- this.key = createKey(initialOptions.key)
162
+ this.key = initialOptions.key
163
163
  this.options = {
164
164
  ...defaultOptions,
165
165
  ...initialOptions,
@@ -173,11 +173,6 @@ export class Throttler<TFn extends AnyFunction> {
173
173
  })
174
174
  }
175
175
 
176
- /**
177
- * Emits a change event for the throttler instance. Mostly useful for devtools.
178
- */
179
- _emit = () => emitChange('Throttler', this)
180
-
181
176
  /**
182
177
  * Updates the throttler options
183
178
  */
package/src/utils.ts CHANGED
@@ -10,18 +10,3 @@ export function parseFunctionOrValue<T, TArgs extends Array<any>>(
10
10
  ): T {
11
11
  return isFunction(value) ? value(...args) : value
12
12
  }
13
-
14
- export function createKey(key?: string): string {
15
- if (key) {
16
- return key
17
- }
18
-
19
- if (
20
- typeof crypto !== 'undefined' &&
21
- typeof crypto.randomUUID === 'function'
22
- ) {
23
- return crypto.randomUUID()
24
- }
25
-
26
- return ''
27
- }