@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,6 +1,6 @@
1
1
  const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let __tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
3
- let __tanstack_solid_store = require("@tanstack/solid-store");
2
+ let _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
3
+ let _tanstack_solid_store = require("@tanstack/solid-store");
4
4
 
5
5
  //#region src/async-batcher/createAsyncBatcher.ts
6
6
  /**
@@ -35,14 +35,24 @@ let __tanstack_solid_store = require("@tanstack/solid-store");
35
35
  *
36
36
  * ## State Management and Selector
37
37
  *
38
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
39
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
40
- * unnecessary re-renders when irrelevant state changes occur.
38
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
39
+ * in two ways:
40
+ *
41
+ * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
42
+ *
43
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
44
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
45
+ * in child components.
46
+ *
47
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
48
+ *
49
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
50
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
51
+ * state changes occur.
41
52
  *
42
53
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
43
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
44
- * full control over when your component updates. Only when you provide a selector will the
45
- * component re-render when the selected state values change.
54
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
55
+ * updates and gives you full control over when your component tracks state changes.
46
56
  *
47
57
  * Available state properties:
48
58
  * - `errorCount`: Number of failed batch executions
@@ -75,7 +85,7 @@ let __tanstack_solid_store = require("@tanstack/solid-store");
75
85
  * }
76
86
  * );
77
87
  *
78
- * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
88
+ * // Opt-in to track items or isExecuting changes (optimized for UI updates)
79
89
  * const asyncBatcher = createAsyncBatcher(
80
90
  * async (items) => {
81
91
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -85,7 +95,7 @@ let __tanstack_solid_store = require("@tanstack/solid-store");
85
95
  * (state) => ({ items: state.items, isExecuting: state.isExecuting })
86
96
  * );
87
97
  *
88
- * // Opt-in to re-render when error state changes (optimized for error handling)
98
+ * // Opt-in to track error state changes (optimized for error handling)
89
99
  * const asyncBatcher = createAsyncBatcher(
90
100
  * async (items) => {
91
101
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -106,11 +116,15 @@ let __tanstack_solid_store = require("@tanstack/solid-store");
106
116
  * ```
107
117
  */
108
118
  function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
109
- const asyncBatcher = new __tanstack_pacer_async_batcher.AsyncBatcher(fn, {
119
+ const asyncBatcher = new _tanstack_pacer_async_batcher.AsyncBatcher(fn, {
110
120
  ...require_PacerProvider.useDefaultPacerOptions().asyncBatcher,
111
121
  ...options
112
122
  });
113
- const state = (0, __tanstack_solid_store.useStore)(asyncBatcher.store, selector);
123
+ asyncBatcher.Subscribe = function Subscribe(props) {
124
+ const selected = (0, _tanstack_solid_store.useStore)(asyncBatcher.store, props.selector);
125
+ return typeof props.children === "function" ? props.children(selected) : props.children;
126
+ };
127
+ const state = (0, _tanstack_solid_store.useStore)(asyncBatcher.store, selector);
114
128
  return {
115
129
  ...asyncBatcher,
116
130
  state
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncBatcher.cjs","names":["AsyncBatcher","useDefaultPacerOptions"],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\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 * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAIA,4CAAqB,IALxB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE+D;CAEhE,MAAM,6CAAiB,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createAsyncBatcher.cjs","names":["AsyncBatcher","useDefaultPacerOptions"],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to track items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncBatcher<TValue, TSelected>\n\n asyncBatcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncBatcher.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAIA,2CACvB,IANoB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,cAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,+CAAoB,aAAa,OAAO,MAAM,SAAS;AAE7D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
@@ -1,9 +1,26 @@
1
1
  import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
2
2
  import { Store } from "@tanstack/solid-store";
3
- import { Accessor } from "solid-js";
3
+ import { Accessor, JSX } from "solid-js";
4
4
 
5
5
  //#region src/async-batcher/createAsyncBatcher.d.ts
6
6
  interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
7
+ /**
8
+ * A Solid component that allows you to subscribe to the batcher state.
9
+ *
10
+ * This is useful for tracking specific parts of the batcher state
11
+ * deep in your component tree without needing to pass a selector to the hook.
12
+ *
13
+ * @example
14
+ * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>
15
+ * {(state) => (
16
+ * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>
17
+ * )}
18
+ * </batcher.Subscribe>
19
+ */
20
+ Subscribe: <TSelected>(props: {
21
+ selector: (state: AsyncBatcherState<TValue>) => TSelected;
22
+ children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
23
+ }) => JSX.Element;
7
24
  /**
8
25
  * Reactive state that will be updated when the batcher state changes
9
26
  *
@@ -49,14 +66,24 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
49
66
  *
50
67
  * ## State Management and Selector
51
68
  *
52
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
53
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
54
- * unnecessary re-renders when irrelevant state changes occur.
69
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
70
+ * in two ways:
71
+ *
72
+ * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
73
+ *
74
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
75
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
76
+ * in child components.
77
+ *
78
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
79
+ *
80
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
81
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
82
+ * state changes occur.
55
83
  *
56
84
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
57
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
58
- * full control over when your component updates. Only when you provide a selector will the
59
- * component re-render when the selected state values change.
85
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
86
+ * updates and gives you full control over when your component tracks state changes.
60
87
  *
61
88
  * Available state properties:
62
89
  * - `errorCount`: Number of failed batch executions
@@ -89,7 +116,7 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
89
116
  * }
90
117
  * );
91
118
  *
92
- * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
119
+ * // Opt-in to track items or isExecuting changes (optimized for UI updates)
93
120
  * const asyncBatcher = createAsyncBatcher(
94
121
  * async (items) => {
95
122
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -99,7 +126,7 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
99
126
  * (state) => ({ items: state.items, isExecuting: state.isExecuting })
100
127
  * );
101
128
  *
102
- * // Opt-in to re-render when error state changes (optimized for error handling)
129
+ * // Opt-in to track error state changes (optimized for error handling)
103
130
  * const asyncBatcher = createAsyncBatcher(
104
131
  * async (items) => {
105
132
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -1,9 +1,26 @@
1
- import { Accessor } from "solid-js";
1
+ import { Accessor, JSX } from "solid-js";
2
2
  import { AsyncBatcher, AsyncBatcherOptions, AsyncBatcherState } from "@tanstack/pacer/async-batcher";
3
3
  import { Store } from "@tanstack/solid-store";
4
4
 
5
5
  //#region src/async-batcher/createAsyncBatcher.d.ts
6
6
  interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TValue>, 'store'> {
7
+ /**
8
+ * A Solid component that allows you to subscribe to the batcher state.
9
+ *
10
+ * This is useful for tracking specific parts of the batcher state
11
+ * deep in your component tree without needing to pass a selector to the hook.
12
+ *
13
+ * @example
14
+ * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>
15
+ * {(state) => (
16
+ * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>
17
+ * )}
18
+ * </batcher.Subscribe>
19
+ */
20
+ Subscribe: <TSelected>(props: {
21
+ selector: (state: AsyncBatcherState<TValue>) => TSelected;
22
+ children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element;
23
+ }) => JSX.Element;
7
24
  /**
8
25
  * Reactive state that will be updated when the batcher state changes
9
26
  *
@@ -49,14 +66,24 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
49
66
  *
50
67
  * ## State Management and Selector
51
68
  *
52
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
53
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
54
- * unnecessary re-renders when irrelevant state changes occur.
69
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
70
+ * in two ways:
71
+ *
72
+ * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
73
+ *
74
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
75
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
76
+ * in child components.
77
+ *
78
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
79
+ *
80
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
81
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
82
+ * state changes occur.
55
83
  *
56
84
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
57
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
58
- * full control over when your component updates. Only when you provide a selector will the
59
- * component re-render when the selected state values change.
85
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
86
+ * updates and gives you full control over when your component tracks state changes.
60
87
  *
61
88
  * Available state properties:
62
89
  * - `errorCount`: Number of failed batch executions
@@ -89,7 +116,7 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
89
116
  * }
90
117
  * );
91
118
  *
92
- * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
119
+ * // Opt-in to track items or isExecuting changes (optimized for UI updates)
93
120
  * const asyncBatcher = createAsyncBatcher(
94
121
  * async (items) => {
95
122
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -99,7 +126,7 @@ interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<AsyncBatcher<TV
99
126
  * (state) => ({ items: state.items, isExecuting: state.isExecuting })
100
127
  * );
101
128
  *
102
- * // Opt-in to re-render when error state changes (optimized for error handling)
129
+ * // Opt-in to track error state changes (optimized for error handling)
103
130
  * const asyncBatcher = createAsyncBatcher(
104
131
  * async (items) => {
105
132
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -35,14 +35,24 @@ import { useStore } from "@tanstack/solid-store";
35
35
  *
36
36
  * ## State Management and Selector
37
37
  *
38
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
39
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
40
- * unnecessary re-renders when irrelevant state changes occur.
38
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
39
+ * in two ways:
40
+ *
41
+ * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**
42
+ *
43
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
44
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
45
+ * in child components.
46
+ *
47
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
48
+ *
49
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
50
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
51
+ * state changes occur.
41
52
  *
42
53
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
43
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
44
- * full control over when your component updates. Only when you provide a selector will the
45
- * component re-render when the selected state values change.
54
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
55
+ * updates and gives you full control over when your component tracks state changes.
46
56
  *
47
57
  * Available state properties:
48
58
  * - `errorCount`: Number of failed batch executions
@@ -75,7 +85,7 @@ import { useStore } from "@tanstack/solid-store";
75
85
  * }
76
86
  * );
77
87
  *
78
- * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)
88
+ * // Opt-in to track items or isExecuting changes (optimized for UI updates)
79
89
  * const asyncBatcher = createAsyncBatcher(
80
90
  * async (items) => {
81
91
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -85,7 +95,7 @@ import { useStore } from "@tanstack/solid-store";
85
95
  * (state) => ({ items: state.items, isExecuting: state.isExecuting })
86
96
  * );
87
97
  *
88
- * // Opt-in to re-render when error state changes (optimized for error handling)
98
+ * // Opt-in to track error state changes (optimized for error handling)
89
99
  * const asyncBatcher = createAsyncBatcher(
90
100
  * async (items) => {
91
101
  * const results = await Promise.all(items.map(item => processItem(item)));
@@ -110,6 +120,10 @@ function createAsyncBatcher(fn, options = {}, selector = () => ({})) {
110
120
  ...useDefaultPacerOptions().asyncBatcher,
111
121
  ...options
112
122
  });
123
+ asyncBatcher.Subscribe = function Subscribe(props) {
124
+ const selected = useStore(asyncBatcher.store, props.selector);
125
+ return typeof props.children === "function" ? props.children(selected) : props.children;
126
+ };
113
127
  const state = useStore(asyncBatcher.store, selector);
114
128
  return {
115
129
  ...asyncBatcher,
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\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 * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to re-render when items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(fn, mergedOptions)\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAI,aAAqB,IALxB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE+D;CAEhE,MAAM,QAAQ,SAAS,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createAsyncBatcher.js","names":[],"sources":["../../src/async-batcher/createAsyncBatcher.ts"],"sourcesContent":["import { AsyncBatcher } from '@tanstack/pacer/async-batcher'\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 {\n AsyncBatcherOptions,\n AsyncBatcherState,\n} from '@tanstack/pacer/async-batcher'\n\nexport interface SolidAsyncBatcher<TValue, TSelected = {}> extends Omit<\n AsyncBatcher<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the batcher state.\n *\n * This is useful for tracking specific parts of the batcher state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <batcher.Subscribe selector={(state) => ({ size: state.size, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>Batch: {state().size} items, {state().isExecuting ? 'Executing...' : 'Idle'}</div>\n * )}\n * </batcher.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the batcher state changes\n *\n * Use this instead of `batcher.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `batcher.state` instead of `batcher.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncBatcherState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible AsyncBatcher instance for managing asynchronous batches of items, exposing Solid signals for all stateful properties.\n *\n * This is the async version of the createBatcher hook. Unlike the sync version, this async batcher:\n * - Handles promises and returns results from batch executions\n * - Provides error handling with configurable error behavior\n * - Tracks success, error, and settle counts separately\n * - Has state tracking for when batches are executing\n * - Returns the result of the batch function execution\n *\n * Features:\n * - Configurable batch size and wait time\n * - Custom batch processing logic via getShouldExecute\n * - Event callbacks for monitoring batch operations\n * - Error handling for failed batch operations\n * - Automatic or manual batch processing\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The batcher collects items and processes them in batches based on:\n * - Maximum batch size (number of items per batch)\n * - Time-based batching (process after X milliseconds)\n * - Custom batch processing logic via getShouldExecute\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and batcher instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together; the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncBatcher instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `batcher.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `errorCount`: Number of failed batch executions\n * - `executionCount`: Total number of batch execution attempts (successful + failed)\n * - `hasError`: Whether the last batch execution resulted in an error\n * - `isExecuting`: Whether a batch execution is currently in progress\n * - `items`: Array of items currently queued for batching\n * - `lastError`: The error from the most recent failed batch execution (if any)\n * - `lastResult`: The result from the most recent successful batch execution\n * - `settleCount`: Number of batch executions that have completed (successful or failed)\n * - `successCount`: Number of successful batch executions\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * {\n * maxSize: 10,\n * wait: 2000,\n * onSuccess: (result) => {\n * console.log('Batch processed successfully:', result);\n * },\n * onError: (error) => {\n * console.error('Batch processing failed:', error);\n * }\n * }\n * );\n *\n * // Opt-in to track items or isExecuting changes (optimized for UI updates)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ items: state.items, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const asyncBatcher = createAsyncBatcher(\n * async (items) => {\n * const results = await Promise.all(items.map(item => processItem(item)));\n * return results;\n * },\n * { maxSize: 10, wait: 2000 },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Add items to batch\n * asyncBatcher.addItem(newItem);\n *\n * // Manually execute batch\n * const result = await asyncBatcher.execute();\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isExecuting } = asyncBatcher.state();\n * ```\n */\nexport function createAsyncBatcher<TValue, TSelected = {}>(\n fn: (items: Array<TValue>) => Promise<any>,\n options: AsyncBatcherOptions<TValue> = {},\n selector: (state: AsyncBatcherState<TValue>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncBatcher<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncBatcher,\n ...options,\n } as AsyncBatcherOptions<TValue>\n\n const asyncBatcher = new AsyncBatcher<TValue>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncBatcher<TValue, TSelected>\n\n asyncBatcher.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncBatcherState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncBatcher.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncBatcher.store, selector)\n\n return {\n ...asyncBatcher,\n state,\n } as SolidAsyncBatcher<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6JA,SAAgB,mBACd,IACA,UAAuC,EAAE,EACzC,kBACG,EAAE,GACiC;CAMtC,MAAM,eAAe,IAAI,aACvB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,cAAa,YAAY,SAAS,UAAqB,OAGpD;EACD,MAAM,WAAW,SAAS,aAAa,OAAO,MAAM,SAAS;AAE7D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,aAAa,OAAO,SAAS;AAEpD,QAAO;EACL,GAAG;EACH;EACD"}
@@ -1,10 +1,10 @@
1
1
  const require_createAsyncBatcher = require('./createAsyncBatcher.cjs');
2
2
 
3
3
  exports.createAsyncBatcher = require_createAsyncBatcher.createAsyncBatcher;
4
- var __tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
5
- Object.keys(__tanstack_pacer_async_batcher).forEach(function (k) {
4
+ var _tanstack_pacer_async_batcher = require("@tanstack/pacer/async-batcher");
5
+ Object.keys(_tanstack_pacer_async_batcher).forEach(function (k) {
6
6
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
7
7
  enumerable: true,
8
- get: function () { return __tanstack_pacer_async_batcher[k]; }
8
+ get: function () { return _tanstack_pacer_async_batcher[k]; }
9
9
  });
10
10
  });
@@ -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_async_debouncer = require("@tanstack/pacer/async-debouncer");
3
+ let _tanstack_solid_store = require("@tanstack/solid-store");
4
+ let _tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer");
5
5
 
6
6
  //#region src/async-debouncer/createAsyncDebouncer.ts
7
7
  /**
@@ -30,14 +30,24 @@ let __tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer"
30
30
  *
31
31
  * ## State Management and Selector
32
32
  *
33
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
34
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
35
- * unnecessary re-renders when irrelevant state changes occur.
33
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
34
+ * in two ways:
35
+ *
36
+ * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
37
+ *
38
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
39
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
40
+ * in child components.
41
+ *
42
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
43
+ *
44
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
45
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
46
+ * state changes occur.
36
47
  *
37
48
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
38
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
39
- * full control over when your component updates. Only when you provide a selector will the
40
- * component re-render when the selected state values change.
49
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
50
+ * updates and gives you full control over when your component tracks state changes.
41
51
  *
42
52
  * Available state properties:
43
53
  * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
@@ -61,7 +71,7 @@ let __tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer"
61
71
  * { wait: 500 }
62
72
  * );
63
73
  *
64
- * // Opt-in to re-render when isPending or isExecuting changes (optimized for loading states)
74
+ * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
65
75
  * const debouncer = createAsyncDebouncer(
66
76
  * async (query: string) => {
67
77
  * const results = await api.search(query);
@@ -71,7 +81,7 @@ let __tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer"
71
81
  * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
72
82
  * );
73
83
  *
74
- * // Opt-in to re-render when error state changes (optimized for error handling)
84
+ * // Opt-in to track error state changes (optimized for error handling)
75
85
  * const debouncer = createAsyncDebouncer(
76
86
  * async (searchTerm) => {
77
87
  * const data = await searchAPI(searchTerm);
@@ -93,11 +103,15 @@ let __tanstack_pacer_async_debouncer = require("@tanstack/pacer/async-debouncer"
93
103
  * ```
94
104
  */
95
105
  function createAsyncDebouncer(fn, options, selector = () => ({})) {
96
- const asyncDebouncer = new __tanstack_pacer_async_debouncer.AsyncDebouncer(fn, {
106
+ const asyncDebouncer = new _tanstack_pacer_async_debouncer.AsyncDebouncer(fn, {
97
107
  ...require_PacerProvider.useDefaultPacerOptions().asyncDebouncer,
98
108
  ...options
99
109
  });
100
- const state = (0, __tanstack_solid_store.useStore)(asyncDebouncer.store, selector);
110
+ asyncDebouncer.Subscribe = function Subscribe(props) {
111
+ const selected = (0, _tanstack_solid_store.useStore)(asyncDebouncer.store, props.selector);
112
+ return typeof props.children === "function" ? props.children(selected) : props.children;
113
+ };
114
+ const state = (0, _tanstack_solid_store.useStore)(asyncDebouncer.store, selector);
101
115
  (0, solid_js.createEffect)(() => {
102
116
  (0, solid_js.onCleanup)(() => {
103
117
  asyncDebouncer.cancel();
@@ -1 +1 @@
1
- {"version":3,"file":"createAsyncDebouncer.cjs","names":["AsyncDebouncer","useDefaultPacerOptions"],"sources":["../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { useStore } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing\n * or input changes where you only want to execute the handler after the events have stopped occurring.\n *\n * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until\n * the function stops being called for the specified delay period.\n *\n * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the debounced function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and debouncer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncDebouncer instance\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 * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastResult`: The result from the most recent successful execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to re-render when isPending or isExecuting changes (optimized for loading states)\n * const debouncer = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to re-render when error state changes (optimized for error handling)\n * const debouncer = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * return data;\n * },\n * {\n * wait: 300,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = debouncer.state();\n * ```\n */\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncDebouncerOptions<TFn>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncDebouncer,\n ...options,\n } as AsyncDebouncerOptions<TFn>\n\n const asyncDebouncer = new AsyncDebouncer<TFn>(fn, mergedOptions)\n\n const state = useStore(asyncDebouncer.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n asyncDebouncer.cancel()\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidAsyncDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAIA,gDAAoB,IALzB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAEgE;CAEjE,MAAM,6CAAiB,eAAe,OAAO,SAAS;AAEtD,kCAAmB;AACjB,gCAAgB;AACd,kBAAe,QAAQ;IACvB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createAsyncDebouncer.cjs","names":["AsyncDebouncer","useDefaultPacerOptions"],"sources":["../../src/async-debouncer/createAsyncDebouncer.ts"],"sourcesContent":["import { AsyncDebouncer } from '@tanstack/pacer/async-debouncer'\nimport { useStore } from '@tanstack/solid-store'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type {\n AsyncDebouncerOptions,\n AsyncDebouncerState,\n} from '@tanstack/pacer/async-debouncer'\nimport type { AnyAsyncFunction } from '@tanstack/pacer/types'\n\nexport interface SolidAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n> extends Omit<AsyncDebouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: AsyncDebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<AsyncDebouncerState<TFn>>>\n}\n\n/**\n * A low-level Solid hook that creates an `AsyncDebouncer` instance to delay execution of an async function.\n *\n * This hook is designed to be flexible and state-management agnostic - it simply returns a debouncer instance that\n * you can integrate with any state management solution (createSignal, etc).\n *\n * Async debouncing ensures that an async function only executes after a specified delay has passed since its last invocation.\n * Each new invocation resets the delay timer. This is useful for handling frequent events like window resizing\n * or input changes where you only want to execute the handler after the events have stopped occurring.\n *\n * Unlike throttling which allows execution at regular intervals, debouncing prevents any execution until\n * the function stops being called for the specified delay period.\n *\n * Unlike the non-async Debouncer, this async version supports returning values from the debounced function,\n * making it ideal for API calls and other async operations where you want the result of the `maybeExecute` call\n * instead of setting the result on a state variable from within the debounced function.\n *\n * Error Handling:\n * - If an `onError` handler is provided, it will be called with the error and debouncer instance\n * - If `throwOnError` is true (default when no onError handler is provided), the error will be thrown\n * - If `throwOnError` is false (default when onError handler is provided), the error will be swallowed\n * - Both onError and throwOnError can be used together - the handler will be called before any error is thrown\n * - The error state can be checked using the underlying AsyncDebouncer instance\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `hasError`: Whether the last execution resulted in an error\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `isExecuting`: Whether an async function execution is currently in progress\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `lastError`: The error from the most recent failed execution (if any)\n * - `lastResult`: The result from the most recent successful execution\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending' | 'executing')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const { maybeExecute } = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending or isExecuting changes (optimized for loading states)\n * const debouncer = createAsyncDebouncer(\n * async (query: string) => {\n * const results = await api.search(query);\n * return results;\n * },\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })\n * );\n *\n * // Opt-in to track error state changes (optimized for error handling)\n * const debouncer = createAsyncDebouncer(\n * async (searchTerm) => {\n * const data = await searchAPI(searchTerm);\n * return data;\n * },\n * {\n * wait: 300,\n * leading: true, // Execute immediately on first call\n * trailing: false, // Skip trailing edge updates\n * onError: (error) => {\n * console.error('API call failed:', error);\n * }\n * },\n * (state) => ({ hasError: state.hasError, lastError: state.lastError })\n * );\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending, isExecuting } = debouncer.state();\n * ```\n */\nexport function createAsyncDebouncer<\n TFn extends AnyAsyncFunction,\n TSelected = {},\n>(\n fn: TFn,\n options: AsyncDebouncerOptions<TFn>,\n selector: (state: AsyncDebouncerState<TFn>) => TSelected = () =>\n ({}) as TSelected,\n): SolidAsyncDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().asyncDebouncer,\n ...options,\n } as AsyncDebouncerOptions<TFn>\n\n const asyncDebouncer = new AsyncDebouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidAsyncDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: AsyncDebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(asyncDebouncer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(asyncDebouncer.store, selector)\n\n createEffect(() => {\n onCleanup(() => {\n asyncDebouncer.cancel()\n })\n })\n\n return {\n ...asyncDebouncer,\n state,\n } as SolidAsyncDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiJA,SAAgB,qBAId,IACA,SACA,kBACG,EAAE,GACgC;CAMrC,MAAM,iBAAiB,IAAIA,+CACzB,IANoB;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,+CAAoB,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,eAAe,OAAO,SAAS;AAEtD,kCAAmB;AACjB,gCAAgB;AACd,kBAAe,QAAQ;IACvB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
@@ -1,10 +1,27 @@
1
1
  import { Store } from "@tanstack/solid-store";
2
- import { Accessor } from "solid-js";
2
+ import { Accessor, JSX } from "solid-js";
3
3
  import { AsyncDebouncer, AsyncDebouncerOptions, AsyncDebouncerState } from "@tanstack/pacer/async-debouncer";
4
4
  import { AnyAsyncFunction } from "@tanstack/pacer/types";
5
5
 
6
6
  //#region src/async-debouncer/createAsyncDebouncer.d.ts
7
7
  interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> extends Omit<AsyncDebouncer<TFn>, 'store'> {
8
+ /**
9
+ * A Solid component that allows you to subscribe to the debouncer state.
10
+ *
11
+ * This is useful for tracking specific parts of the debouncer state
12
+ * deep in your component tree without needing to pass a selector to the hook.
13
+ *
14
+ * @example
15
+ * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })}>
16
+ * {(state) => (
17
+ * <div>{state().isPending ? 'Waiting...' : state().isExecuting ? 'Executing...' : 'Ready'}</div>
18
+ * )}
19
+ * </debouncer.Subscribe>
20
+ */
21
+ Subscribe: <TSelected>(props: {
22
+ selector: (state: AsyncDebouncerState<TFn>) => 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 debouncer state changes
10
27
  *
@@ -44,14 +61,24 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
44
61
  *
45
62
  * ## State Management and Selector
46
63
  *
47
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
48
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
49
- * unnecessary re-renders when irrelevant state changes occur.
64
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
65
+ * in two ways:
66
+ *
67
+ * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
68
+ *
69
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
70
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
71
+ * in child components.
72
+ *
73
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
74
+ *
75
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
76
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
77
+ * state changes occur.
50
78
  *
51
79
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
52
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
53
- * full control over when your component updates. Only when you provide a selector will the
54
- * component re-render when the selected state values change.
80
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
81
+ * updates and gives you full control over when your component tracks state changes.
55
82
  *
56
83
  * Available state properties:
57
84
  * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
@@ -75,7 +102,7 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
75
102
  * { wait: 500 }
76
103
  * );
77
104
  *
78
- * // Opt-in to re-render when isPending or isExecuting changes (optimized for loading states)
105
+ * // Opt-in to track isPending or isExecuting changes (optimized for loading states)
79
106
  * const debouncer = createAsyncDebouncer(
80
107
  * async (query: string) => {
81
108
  * const results = await api.search(query);
@@ -85,7 +112,7 @@ interface SolidAsyncDebouncer<TFn extends AnyAsyncFunction, TSelected = {}> exte
85
112
  * (state) => ({ isPending: state.isPending, isExecuting: state.isExecuting })
86
113
  * );
87
114
  *
88
- * // Opt-in to re-render when error state changes (optimized for error handling)
115
+ * // Opt-in to track error state changes (optimized for error handling)
89
116
  * const debouncer = createAsyncDebouncer(
90
117
  * async (searchTerm) => {
91
118
  * const data = await searchAPI(searchTerm);