@tanstack/solid-pacer 0.17.0 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/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 +1 -1
  93. package/src/async-batcher/createAsyncBatcher.ts +51 -10
  94. package/src/async-debouncer/createAsyncDebouncer.ts +51 -10
  95. package/src/async-queuer/createAsyncQueuer.ts +51 -10
  96. package/src/async-rate-limiter/createAsyncRateLimiter.ts +114 -28
  97. package/src/async-throttler/createAsyncThrottler.ts +51 -10
  98. package/src/batcher/createBatcher.ts +51 -10
  99. package/src/debouncer/createDebouncer.ts +52 -11
  100. package/src/queuer/createQueuedSignal.ts +8 -8
  101. package/src/queuer/createQueuer.ts +51 -10
  102. package/src/rate-limiter/createRateLimiter.ts +103 -21
  103. package/src/throttler/createThrottledSignal.ts +1 -1
  104. package/src/throttler/createThrottledValue.ts +1 -1
  105. package/src/throttler/createThrottler.ts +59 -11
@@ -1,10 +1,27 @@
1
- import { Accessor } from "solid-js";
1
+ import { Accessor, JSX } from "solid-js";
2
2
  import { Store } from "@tanstack/solid-store";
3
3
  import { Debouncer, DebouncerOptions, DebouncerState } from "@tanstack/pacer/debouncer";
4
4
  import { AnyFunction } from "@tanstack/pacer/types";
5
5
 
6
6
  //#region src/debouncer/createDebouncer.d.ts
7
7
  interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<Debouncer<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 })}>
16
+ * {(state) => (
17
+ * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>
18
+ * )}
19
+ * </debouncer.Subscribe>
20
+ */
21
+ Subscribe: <TSelected>(props: {
22
+ selector: (state: DebouncerState<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
  *
@@ -35,14 +52,24 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
35
52
  *
36
53
  * ## State Management and Selector
37
54
  *
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.
55
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
56
+ * in two ways:
57
+ *
58
+ * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
59
+ *
60
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
61
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
62
+ * in child components.
63
+ *
64
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
65
+ *
66
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
67
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
68
+ * state changes occur.
41
69
  *
42
70
  * **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.
71
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
72
+ * updates and gives you full control over when your component tracks state changes.
46
73
  *
47
74
  * Available state properties:
48
75
  * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
@@ -59,21 +86,21 @@ interface SolidDebouncer<TFn extends AnyFunction, TSelected = {}> extends Omit<D
59
86
  * { wait: 500 }
60
87
  * );
61
88
  *
62
- * // Opt-in to re-render when isPending changes (optimized for loading states)
89
+ * // Opt-in to track isPending changes (optimized for loading states)
63
90
  * const debouncer = createDebouncer(
64
91
  * (query: string) => fetchSearchResults(query),
65
92
  * { wait: 500 },
66
93
  * (state) => ({ isPending: state.isPending })
67
94
  * );
68
95
  *
69
- * // Opt-in to re-render when executionCount changes (optimized for tracking execution)
96
+ * // Opt-in to track executionCount changes (optimized for tracking execution)
70
97
  * const debouncer = createDebouncer(
71
98
  * (query: string) => fetchSearchResults(query),
72
99
  * { wait: 500 },
73
100
  * (state) => ({ executionCount: state.executionCount })
74
101
  * );
75
102
  *
76
- * // Multiple state properties - re-render when any of these change
103
+ * // Multiple state properties - track when any of these change
77
104
  * const debouncer = createDebouncer(
78
105
  * (query: string) => fetchSearchResults(query),
79
106
  * { wait: 500 },
@@ -21,14 +21,24 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
21
21
  *
22
22
  * ## State Management and Selector
23
23
  *
24
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
25
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
26
- * unnecessary re-renders when irrelevant state changes occur.
24
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
25
+ * in two ways:
26
+ *
27
+ * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**
28
+ *
29
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
30
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
31
+ * in child components.
32
+ *
33
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
34
+ *
35
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
36
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
37
+ * state changes occur.
27
38
  *
28
39
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
29
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
30
- * full control over when your component updates. Only when you provide a selector will the
31
- * component re-render when the selected state values change.
40
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
41
+ * updates and gives you full control over when your component tracks state changes.
32
42
  *
33
43
  * Available state properties:
34
44
  * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge
@@ -45,21 +55,21 @@ import { Debouncer } from "@tanstack/pacer/debouncer";
45
55
  * { wait: 500 }
46
56
  * );
47
57
  *
48
- * // Opt-in to re-render when isPending changes (optimized for loading states)
58
+ * // Opt-in to track isPending changes (optimized for loading states)
49
59
  * const debouncer = createDebouncer(
50
60
  * (query: string) => fetchSearchResults(query),
51
61
  * { wait: 500 },
52
62
  * (state) => ({ isPending: state.isPending })
53
63
  * );
54
64
  *
55
- * // Opt-in to re-render when executionCount changes (optimized for tracking execution)
65
+ * // Opt-in to track executionCount changes (optimized for tracking execution)
56
66
  * const debouncer = createDebouncer(
57
67
  * (query: string) => fetchSearchResults(query),
58
68
  * { wait: 500 },
59
69
  * (state) => ({ executionCount: state.executionCount })
60
70
  * );
61
71
  *
62
- * // Multiple state properties - re-render when any of these change
72
+ * // Multiple state properties - track when any of these change
63
73
  * const debouncer = createDebouncer(
64
74
  * (query: string) => fetchSearchResults(query),
65
75
  * { wait: 500 },
@@ -84,6 +94,10 @@ function createDebouncer(fn, options, selector = () => ({})) {
84
94
  ...useDefaultPacerOptions().debouncer,
85
95
  ...options
86
96
  });
97
+ asyncDebouncer.Subscribe = function Subscribe(props) {
98
+ const selected = useStore(asyncDebouncer.store, props.selector);
99
+ return typeof props.children === "function" ? props.children(selected) : props.children;
100
+ };
87
101
  const state = useStore(asyncDebouncer.store, selector);
88
102
  createEffect(() => {
89
103
  onCleanup(() => {
@@ -1 +1 @@
1
- {"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<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<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. 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 * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to re-render when isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to re-render when executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - re-render when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as DebouncerOptions<TFn>\n\n const asyncDebouncer = new Debouncer<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 SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyGA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,iBAAiB,IAAI,UAAe,IALpB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2D;CAE5D,MAAM,QAAQ,SAAS,eAAe,OAAO,SAAS;AAEtD,oBAAmB;AACjB,kBAAgB;AACd,kBAAe,QAAQ;IACvB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createDebouncer.js","names":[],"sources":["../../src/debouncer/createDebouncer.ts"],"sourcesContent":["import { Debouncer } from '@tanstack/pacer/debouncer'\nimport { createEffect, onCleanup } from 'solid-js'\nimport { useStore } from '@tanstack/solid-store'\nimport { useDefaultPacerOptions } from '../provider/PacerProvider'\nimport type { Store } from '@tanstack/solid-store'\nimport type { Accessor, JSX } from 'solid-js'\nimport type { AnyFunction } from '@tanstack/pacer/types'\nimport type {\n DebouncerOptions,\n DebouncerState,\n} from '@tanstack/pacer/debouncer'\n\nexport interface SolidDebouncer<\n TFn extends AnyFunction,\n TSelected = {},\n> extends Omit<Debouncer<TFn>, 'store'> {\n /**\n * A Solid component that allows you to subscribe to the debouncer state.\n *\n * This is useful for tracking specific parts of the debouncer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <debouncer.Subscribe selector={(state) => ({ isPending: state.isPending })}>\n * {(state) => (\n * <div>{state().isPending ? 'Waiting...' : 'Ready'}</div>\n * )}\n * </debouncer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the debouncer state changes\n *\n * Use this instead of `debouncer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `debouncer.state` instead of `debouncer.store.state` if you want to read reactive state.\n * The state on the store object is not reactive, as it has not been wrapped in a `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<DebouncerState<TFn>>>\n}\n\n/**\n * A Solid hook that creates and manages a Debouncer instance.\n *\n * This is a lower-level hook that provides direct access to the Debouncer's functionality without\n * any built-in state management. This allows you to integrate it with any state management solution\n * you prefer (createSignal, Redux, Zustand, etc.).\n *\n * This hook provides debouncing functionality to limit how often a function can be called,\n * waiting for a specified delay before executing the latest call. This is useful for handling\n * frequent events like window resizing, scroll events, or real-time search inputs.\n *\n * The debouncer will only execute the function after the specified wait time has elapsed\n * since the last call. If the function is called again before the wait time expires, the\n * timer resets and starts waiting again.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. You can subscribe to state changes\n * in two ways:\n *\n * **1. Using `debouncer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `canLeadingExecute`: Whether the debouncer can execute on the leading edge\n * - `executionCount`: Number of function executions that have been completed\n * - `isPending`: Whether the debouncer is waiting for the timeout to trigger execution\n * - `lastArgs`: The arguments from the most recent call to maybeExecute\n * - `status`: Current execution status ('disabled' | 'idle' | 'pending')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 }\n * );\n *\n * // Opt-in to track isPending changes (optimized for loading states)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ isPending: state.isPending })\n * );\n *\n * // Opt-in to track executionCount changes (optimized for tracking execution)\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({ executionCount: state.executionCount })\n * );\n *\n * // Multiple state properties - track when any of these change\n * const debouncer = createDebouncer(\n * (query: string) => fetchSearchResults(query),\n * { wait: 500 },\n * (state) => ({\n * isPending: state.isPending,\n * executionCount: state.executionCount,\n * status: state.status\n * })\n * );\n *\n * // In an event handler\n * const handleChange = (e) => {\n * debouncer.maybeExecute(e.target.value);\n * };\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { isPending } = debouncer.state();\n * ```\n */\nexport function createDebouncer<TFn extends AnyFunction, TSelected = {}>(\n fn: TFn,\n options: DebouncerOptions<TFn>,\n selector: (state: DebouncerState<TFn>) => TSelected = () => ({}) as TSelected,\n): SolidDebouncer<TFn, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().debouncer,\n ...options,\n } as DebouncerOptions<TFn>\n\n const asyncDebouncer = new Debouncer<TFn>(\n fn,\n mergedOptions,\n ) as unknown as SolidDebouncer<TFn, TSelected>\n\n asyncDebouncer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: DebouncerState<TFn>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = 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 SolidDebouncer<TFn, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoIA,SAAgB,gBACd,IACA,SACA,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,iBAAiB,IAAI,UACzB,IANoB;EACpB,GAAG,wBAAwB,CAAC;EAC5B,GAAG;EACJ,CAKA;AAED,gBAAe,YAAY,SAAS,UAAqB,OAGtD;EACD,MAAM,WAAW,SAAS,eAAe,OAAO,MAAM,SAAS;AAE/D,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,QAAQ,SAAS,eAAe,OAAO,SAAS;AAEtD,oBAAmB;AACjB,kBAAgB;AACd,kBAAe,QAAQ;IACvB;GACF;AAEF,QAAO;EACL,GAAG;EACH;EACD"}
@@ -5,10 +5,10 @@ const require_createDebouncedValue = require('./createDebouncedValue.cjs');
5
5
  exports.createDebouncedSignal = require_createDebouncedSignal.createDebouncedSignal;
6
6
  exports.createDebouncedValue = require_createDebouncedValue.createDebouncedValue;
7
7
  exports.createDebouncer = require_createDebouncer.createDebouncer;
8
- var __tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
9
- Object.keys(__tanstack_pacer_debouncer).forEach(function (k) {
8
+ var _tanstack_pacer_debouncer = require("@tanstack/pacer/debouncer");
9
+ Object.keys(_tanstack_pacer_debouncer).forEach(function (k) {
10
10
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
11
11
  enumerable: true,
12
- get: function () { return __tanstack_pacer_debouncer[k]; }
12
+ get: function () { return _tanstack_pacer_debouncer[k]; }
13
13
  });
14
14
  });
package/dist/index.cjs CHANGED
@@ -37,10 +37,10 @@ exports.createThrottledValue = require_createThrottledValue.createThrottledValue
37
37
  exports.createThrottler = require_createThrottler.createThrottler;
38
38
  exports.useDefaultPacerOptions = require_PacerProvider.useDefaultPacerOptions;
39
39
  exports.usePacerContext = require_PacerProvider.usePacerContext;
40
- var __tanstack_pacer = require("@tanstack/pacer");
41
- Object.keys(__tanstack_pacer).forEach(function (k) {
40
+ var _tanstack_pacer = require("@tanstack/pacer");
41
+ Object.keys(_tanstack_pacer).forEach(function (k) {
42
42
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
43
43
  enumerable: true,
44
- get: function () { return __tanstack_pacer[k]; }
44
+ get: function () { return _tanstack_pacer[k]; }
45
45
  });
46
46
  });
@@ -19,13 +19,13 @@ const require_createQueuer = require('./createQueuer.cjs');
19
19
  * ## State Management and Selector
20
20
  *
21
21
  * The primitive uses Solid's reactive state management via the underlying queuer instance.
22
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
23
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
22
+ * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
23
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
24
24
  *
25
25
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
26
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
27
- * full control over when your component updates. Only when you provide a selector will the
28
- * component re-render when the selected state values change.
26
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
27
+ * full control over when your component tracks state changes. Only when you provide a selector will the
28
+ * component track changes to the selected state values.
29
29
  *
30
30
  * Available queuer state properties:
31
31
  * - `executionCount`: Number of items that have been processed by the queuer
@@ -54,7 +54,7 @@ const require_createQueuer = require('./createQueuer.cjs');
54
54
  * }
55
55
  * );
56
56
  *
57
- * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
57
+ * // Opt-in to track queue contents changes (optimized for displaying queue items)
58
58
  * const [items, addItem, queue] = createQueuedSignal(
59
59
  * (item) => console.log('Processing:', item),
60
60
  * { started: true, wait: 1000 },
@@ -65,7 +65,7 @@ const require_createQueuer = require('./createQueuer.cjs');
65
65
  * })
66
66
  * );
67
67
  *
68
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
68
+ * // Opt-in to track processing state changes (optimized for loading indicators)
69
69
  * const [items, addItem, queue] = createQueuedSignal(
70
70
  * (item) => console.log('Processing:', item),
71
71
  * { started: true, wait: 1000 },
@@ -77,7 +77,7 @@ const require_createQueuer = require('./createQueuer.cjs');
77
77
  * })
78
78
  * );
79
79
  *
80
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
80
+ * // Opt-in to track execution metrics changes (optimized for stats display)
81
81
  * const [items, addItem, queue] = createQueuedSignal(
82
82
  * (item) => console.log('Processing:', item),
83
83
  * { started: true, wait: 1000 },
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuedSignal.cjs","names":["createQueuer"],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer } from './createQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing 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 queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to re-render when queue contents change (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQA,kCAAa,IAAI,SAAS,SAAS;AAEjD,QAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}
1
+ {"version":3,"file":"createQueuedSignal.cjs","names":["createQueuer"],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer } from './createQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will the\n * component track changes to the selected state values.\n *\n * Available queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to track queue contents changes (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to track processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQA,kCAAa,IAAI,SAAS,SAAS;AAEjD,QAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}
@@ -21,13 +21,13 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
21
21
  * ## State Management and Selector
22
22
  *
23
23
  * The primitive uses Solid's reactive state management via the underlying queuer instance.
24
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
25
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
24
+ * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
25
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
26
26
  *
27
27
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
28
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
29
- * full control over when your component updates. Only when you provide a selector will the
30
- * component re-render when the selected state values change.
28
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
29
+ * full control over when your component tracks state changes. Only when you provide a selector will the
30
+ * component track changes to the selected state values.
31
31
  *
32
32
  * Available queuer state properties:
33
33
  * - `executionCount`: Number of items that have been processed by the queuer
@@ -56,7 +56,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
56
56
  * }
57
57
  * );
58
58
  *
59
- * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
59
+ * // Opt-in to track queue contents changes (optimized for displaying queue items)
60
60
  * const [items, addItem, queue] = createQueuedSignal(
61
61
  * (item) => console.log('Processing:', item),
62
62
  * { started: true, wait: 1000 },
@@ -67,7 +67,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
67
67
  * })
68
68
  * );
69
69
  *
70
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
70
+ * // Opt-in to track processing state changes (optimized for loading indicators)
71
71
  * const [items, addItem, queue] = createQueuedSignal(
72
72
  * (item) => console.log('Processing:', item),
73
73
  * { started: true, wait: 1000 },
@@ -79,7 +79,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
79
79
  * })
80
80
  * );
81
81
  *
82
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
82
+ * // Opt-in to track execution metrics changes (optimized for stats display)
83
83
  * const [items, addItem, queue] = createQueuedSignal(
84
84
  * (item) => console.log('Processing:', item),
85
85
  * { started: true, wait: 1000 },
@@ -21,13 +21,13 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
21
21
  * ## State Management and Selector
22
22
  *
23
23
  * The primitive uses Solid's reactive state management via the underlying queuer instance.
24
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
25
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
24
+ * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
25
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
26
26
  *
27
27
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
28
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
29
- * full control over when your component updates. Only when you provide a selector will the
30
- * component re-render when the selected state values change.
28
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
29
+ * full control over when your component tracks state changes. Only when you provide a selector will the
30
+ * component track changes to the selected state values.
31
31
  *
32
32
  * Available queuer state properties:
33
33
  * - `executionCount`: Number of items that have been processed by the queuer
@@ -56,7 +56,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
56
56
  * }
57
57
  * );
58
58
  *
59
- * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
59
+ * // Opt-in to track queue contents changes (optimized for displaying queue items)
60
60
  * const [items, addItem, queue] = createQueuedSignal(
61
61
  * (item) => console.log('Processing:', item),
62
62
  * { started: true, wait: 1000 },
@@ -67,7 +67,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
67
67
  * })
68
68
  * );
69
69
  *
70
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
70
+ * // Opt-in to track processing state changes (optimized for loading indicators)
71
71
  * const [items, addItem, queue] = createQueuedSignal(
72
72
  * (item) => console.log('Processing:', item),
73
73
  * { started: true, wait: 1000 },
@@ -79,7 +79,7 @@ import { QueuerOptions, QueuerState } from "@tanstack/pacer/queuer";
79
79
  * })
80
80
  * );
81
81
  *
82
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
82
+ * // Opt-in to track execution metrics changes (optimized for stats display)
83
83
  * const [items, addItem, queue] = createQueuedSignal(
84
84
  * (item) => console.log('Processing:', item),
85
85
  * { started: true, wait: 1000 },
@@ -19,13 +19,13 @@ import { createQueuer } from "./createQueuer.js";
19
19
  * ## State Management and Selector
20
20
  *
21
21
  * The primitive uses Solid's reactive state management via the underlying queuer instance.
22
- * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,
23
- * optimizing performance by preventing unnecessary re-renders when irrelevant state changes occur.
22
+ * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,
23
+ * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.
24
24
  *
25
25
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
26
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
27
- * full control over when your component updates. Only when you provide a selector will the
28
- * component re-render when the selected state values change.
26
+ * tracking by providing a selector function. This prevents unnecessary updates and gives you
27
+ * full control over when your component tracks state changes. Only when you provide a selector will the
28
+ * component track changes to the selected state values.
29
29
  *
30
30
  * Available queuer state properties:
31
31
  * - `executionCount`: Number of items that have been processed by the queuer
@@ -54,7 +54,7 @@ import { createQueuer } from "./createQueuer.js";
54
54
  * }
55
55
  * );
56
56
  *
57
- * // Opt-in to re-render when queue contents change (optimized for displaying queue items)
57
+ * // Opt-in to track queue contents changes (optimized for displaying queue items)
58
58
  * const [items, addItem, queue] = createQueuedSignal(
59
59
  * (item) => console.log('Processing:', item),
60
60
  * { started: true, wait: 1000 },
@@ -65,7 +65,7 @@ import { createQueuer } from "./createQueuer.js";
65
65
  * })
66
66
  * );
67
67
  *
68
- * // Opt-in to re-render when processing state changes (optimized for loading indicators)
68
+ * // Opt-in to track processing state changes (optimized for loading indicators)
69
69
  * const [items, addItem, queue] = createQueuedSignal(
70
70
  * (item) => console.log('Processing:', item),
71
71
  * { started: true, wait: 1000 },
@@ -77,7 +77,7 @@ import { createQueuer } from "./createQueuer.js";
77
77
  * })
78
78
  * );
79
79
  *
80
- * // Opt-in to re-render when execution metrics change (optimized for stats display)
80
+ * // Opt-in to track execution metrics changes (optimized for stats display)
81
81
  * const [items, addItem, queue] = createQueuedSignal(
82
82
  * (item) => console.log('Processing:', item),
83
83
  * { started: true, wait: 1000 },
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuedSignal.js","names":[],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer } from './createQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger a re-render,\n * optimizing performance by preventing 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 queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to re-render when queue contents change (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to re-render when processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQ,aAAa,IAAI,SAAS,SAAS;AAEjD,QAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}
1
+ {"version":3,"file":"createQueuedSignal.js","names":[],"sources":["../../src/queuer/createQueuedSignal.ts"],"sourcesContent":["import { createQueuer } from './createQueuer'\nimport type { SolidQueuer } from './createQueuer'\nimport type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\n/**\n * A Solid primitive that creates a queuer with managed state, combining Solid's signals with queuing functionality.\n * This primitive provides both the current queue state and queue control methods.\n *\n * The queue state is automatically updated whenever items are added, removed, or reordered in the queue.\n * All queue operations are reflected in the state array returned by the primitive.\n *\n * The queue can be started and stopped to automatically process items at a specified interval,\n * making it useful as a scheduler. When started, it will process one item per tick, with an\n * optional wait time between ticks.\n *\n * The primitive returns a tuple containing:\n * - The current queue state as an array\n * - The queue instance with methods for queue manipulation\n *\n * ## State Management and Selector\n *\n * The primitive uses Solid's reactive state management via the underlying queuer instance.\n * The `selector` parameter allows you to specify which queuer state changes will trigger reactive updates,\n * optimizing performance by preventing unnecessary updates when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary updates and gives you\n * full control over when your component tracks state changes. Only when you provide a selector will the\n * component track changes to the selected state values.\n *\n * Available queuer state properties:\n * - `executionCount`: Number of items that have been processed by the queuer\n * - `expirationCount`: Number of items that have been removed due to expiration\n * - `isEmpty`: Whether the queuer has no items to process\n * - `isFull`: Whether the queuer has reached its maximum capacity\n * - `isIdle`: Whether the queuer is not currently processing any items\n * - `isRunning`: Whether the queuer is active and will process items automatically\n * - `items`: Array of items currently waiting to be processed\n * - `itemTimestamps`: Timestamps when items were added for expiration tracking\n * - `pendingTick`: Whether the queuer has a pending timeout for processing the next item\n * - `rejectionCount`: Number of items that have been rejected from being added\n * - `size`: Number of items currently in the queue\n * - `status`: Current processing status ('idle' | 'running' | 'stopped')\n *\n * @example\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * {\n * initialItems: ['item1', 'item2'],\n * started: true,\n * wait: 1000,\n * getPriority: (item) => item.priority\n * }\n * );\n *\n * // Opt-in to track queue contents changes (optimized for displaying queue items)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * items: state.items,\n * size: state.size,\n * isEmpty: state.isEmpty\n * })\n * );\n *\n * // Opt-in to track processing state changes (optimized for loading indicators)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * isRunning: state.isRunning,\n * isIdle: state.isIdle,\n * status: state.status,\n * pendingTick: state.pendingTick\n * })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for stats display)\n * const [items, addItem, queue] = createQueuedSignal(\n * (item) => console.log('Processing:', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * expirationCount: state.expirationCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to queue\n * const handleAdd = (item) => {\n * addItem(item);\n * };\n *\n * // Start automatic processing\n * const startProcessing = () => {\n * queue.start();\n * };\n *\n * // Stop automatic processing\n * const stopProcessing = () => {\n * queue.stop();\n * };\n *\n * // Manual processing still available\n * const handleProcess = () => {\n * const nextItem = queue.getNextItem();\n * if (nextItem) {\n * processItem(nextItem);\n * }\n * };\n *\n * // Access the selected queuer state (will be empty object {} unless selector provided)\n * const { size, isRunning, executionCount } = queue.state;\n * ```\n */\nexport function createQueuedSignal<\n TValue,\n TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<\n QueuerState<TValue>,\n 'items'\n >,\n>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = (state) =>\n ({ items: state.items }) as TSelected,\n): [\n () => Array<TValue>,\n SolidQueuer<TValue, TSelected>['addItem'],\n SolidQueuer<TValue, TSelected>,\n] {\n const queue = createQueuer(fn, options, selector)\n\n return [() => queue.state().items, queue.addItem, queue]\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsHA,SAAgB,mBAOd,IACA,UAAiC,EAAE,EACnC,YAAuD,WACpD,EAAE,OAAO,MAAM,OAAO,GAKzB;CACA,MAAM,QAAQ,aAAa,IAAI,SAAS,SAAS;AAEjD,QAAO;QAAO,MAAM,OAAO,CAAC;EAAO,MAAM;EAAS;EAAM"}
@@ -1,6 +1,6 @@
1
1
  const require_PacerProvider = require('../provider/PacerProvider.cjs');
2
- let __tanstack_solid_store = require("@tanstack/solid-store");
3
- let __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
2
+ let _tanstack_solid_store = require("@tanstack/solid-store");
3
+ let _tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
4
4
 
5
5
  //#region src/queuer/createQueuer.ts
6
6
  /**
@@ -22,14 +22,24 @@ let __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
22
22
  *
23
23
  * ## State Management and Selector
24
24
  *
25
- * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you
26
- * to specify which state changes will trigger a re-render, optimizing performance by preventing
27
- * unnecessary re-renders when irrelevant state changes occur.
25
+ * The hook uses TanStack Store for reactive state management. You can subscribe to state changes
26
+ * in two ways:
27
+ *
28
+ * **1. Using `queuer.Subscribe` component (Recommended for component tree subscriptions)**
29
+ *
30
+ * Use the `Subscribe` component to subscribe to state changes deep in your component tree without
31
+ * needing to pass a selector to the hook. This is ideal when you want to subscribe to state
32
+ * in child components.
33
+ *
34
+ * **2. Using the `selector` parameter (For hook-level subscriptions)**
35
+ *
36
+ * The `selector` parameter allows you to specify which state changes will trigger reactive updates
37
+ * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant
38
+ * state changes occur.
28
39
  *
29
40
  * **By default, there will be no reactive state subscriptions** and you must opt-in to state
30
- * tracking by providing a selector function. This prevents unnecessary re-renders and gives you
31
- * full control over when your component updates. Only when you provide a selector will the
32
- * component re-render when the selected state values change.
41
+ * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary
42
+ * updates and gives you full control over when your component tracks state changes.
33
43
  *
34
44
  * Available state properties:
35
45
  * - `executionCount`: Number of items that have been processed
@@ -52,14 +62,14 @@ let __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
52
62
  * }
53
63
  * );
54
64
  *
55
- * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)
65
+ * // Opt-in to track items or isRunning changes (optimized for UI updates)
56
66
  * const queue = createQueuer(
57
67
  * (item) => console.log('Processing', item),
58
68
  * { started: true, wait: 1000 },
59
69
  * (state) => ({ items: state.items, isRunning: state.isRunning })
60
70
  * );
61
71
  *
62
- * // Opt-in to re-render when execution metrics change (optimized for tracking progress)
72
+ * // Opt-in to track execution metrics changes (optimized for tracking progress)
63
73
  * const queue = createQueuer(
64
74
  * (item) => console.log('Processing', item),
65
75
  * { started: true, wait: 1000 },
@@ -82,11 +92,15 @@ let __tanstack_pacer_queuer = require("@tanstack/pacer/queuer");
82
92
  * ```
83
93
  */
84
94
  function createQueuer(fn, options = {}, selector = () => ({})) {
85
- const queuer = new __tanstack_pacer_queuer.Queuer(fn, {
95
+ const queuer = new _tanstack_pacer_queuer.Queuer(fn, {
86
96
  ...require_PacerProvider.useDefaultPacerOptions().queuer,
87
97
  ...options
88
98
  });
89
- const state = (0, __tanstack_solid_store.useStore)(queuer.store, selector);
99
+ queuer.Subscribe = function Subscribe(props) {
100
+ const selected = (0, _tanstack_solid_store.useStore)(queuer.store, props.selector);
101
+ return typeof props.children === "function" ? props.children(selected) : props.children;
102
+ };
103
+ const state = (0, _tanstack_solid_store.useStore)(queuer.store, selector);
90
104
  return {
91
105
  ...queuer,
92
106
  state
@@ -1 +1 @@
1
- {"version":3,"file":"createQueuer.cjs","names":["Queuer","useDefaultPacerOptions"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\n *\n * ## State Management and Selector\n *\n * The hook uses TanStack Store for reactive state management. The `selector` parameter allows you\n * to specify which state changes will trigger a re-render, optimizing performance by preventing\n * unnecessary re-renders when irrelevant state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function. This prevents unnecessary re-renders and gives you\n * full control over when your component updates. Only when you provide a selector will the\n * component re-render when the selected state values change.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to re-render when items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to re-render when execution metrics change (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as QueuerOptions<TValue>\n\n const queuer = new Queuer(fn, mergedOptions)\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuGA,SAAgB,aACd,IACA,UAAiC,EAAE,EACnC,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,SAAS,IAAIA,+BAAO,IALJ;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2C;CAE5C,MAAM,6CAAiB,OAAO,OAAO,SAAS;AAE9C,QAAO;EACL,GAAG;EACH;EACD"}
1
+ {"version":3,"file":"createQueuer.cjs","names":["Queuer","useDefaultPacerOptions"],"sources":["../../src/queuer/createQueuer.ts"],"sourcesContent":["import { Queuer } from '@tanstack/pacer/queuer'\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 { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'\n\nexport interface SolidQueuer<TValue, TSelected = {}> extends Omit<\n Queuer<TValue>,\n 'store'\n> {\n /**\n * A Solid component that allows you to subscribe to the queuer state.\n *\n * This is useful for tracking specific parts of the queuer state\n * deep in your component tree without needing to pass a selector to the hook.\n *\n * @example\n * <queuer.Subscribe selector={(state) => ({ size: state.size, isRunning: state.isRunning })}>\n * {(state) => (\n * <div>Queue: {state().size} items, {state().isRunning ? 'Processing' : 'Idle'}</div>\n * )}\n * </queuer.Subscribe>\n */\n Subscribe: <TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) => JSX.Element\n /**\n * Reactive state that will be updated when the queuer state changes\n *\n * Use this instead of `queuer.store.state`\n */\n readonly state: Accessor<Readonly<TSelected>>\n /**\n * @deprecated Use `queuer.state` instead of `queuer.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<QueuerState<TValue>>>\n}\n\n/**\n * Creates a Solid-compatible Queuer instance for managing a synchronous queue of items, exposing Solid signals for all stateful properties.\n *\n * Features:\n * - Synchronous processing of items using the provided `fn` function\n * - FIFO (First In First Out) or LIFO (Last In First Out) queue behavior\n * - Priority queueing via `getPriority` or item `priority` property\n * - Item expiration and removal of stale items\n * - Configurable wait time between processing items\n * - Pause/resume processing\n * - Callbacks for queue state changes, execution, rejection, and expiration\n * - All stateful properties (items, counts, etc.) are exposed as Solid signals for reactivity\n *\n * The queue processes items synchronously in order, with optional delays between each item. When started, it will process one item per tick, with an optional wait time between ticks. You can pause and resume processing with `stop()` and `start()`.\n *\n * By default, the queue uses FIFO behavior, but you can configure LIFO or double-ended queueing by specifying the position when adding or removing items.\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 `queuer.Subscribe` component (Recommended for component tree subscriptions)**\n *\n * Use the `Subscribe` component to subscribe to state changes deep in your component tree without\n * needing to pass a selector to the hook. This is ideal when you want to subscribe to state\n * in child components.\n *\n * **2. Using the `selector` parameter (For hook-level subscriptions)**\n *\n * The `selector` parameter allows you to specify which state changes will trigger reactive updates\n * at the hook level, optimizing performance by preventing unnecessary updates when irrelevant\n * state changes occur.\n *\n * **By default, there will be no reactive state subscriptions** and you must opt-in to state\n * tracking by providing a selector function or using the `Subscribe` component. This prevents unnecessary\n * updates and gives you full control over when your component tracks state changes.\n *\n * Available state properties:\n * - `executionCount`: Number of items that have been processed\n * - `isRunning`: Whether the queuer is currently running (not stopped)\n * - `items`: Array of items currently queued for processing\n * - `rejectionCount`: Number of items that were rejected (expired or failed validation)\n *\n * Example usage:\n * ```tsx\n * // Default behavior - no reactive state subscriptions\n * const queue = createQueuer(\n * (item) => {\n * // process item synchronously\n * console.log('Processing', item);\n * },\n * {\n * started: true, // Start processing immediately\n * wait: 1000, // Process one item every second\n * getPriority: (item) => item.priority // Process higher priority items first\n * }\n * );\n *\n * // Opt-in to track items or isRunning changes (optimized for UI updates)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({ items: state.items, isRunning: state.isRunning })\n * );\n *\n * // Opt-in to track execution metrics changes (optimized for tracking progress)\n * const queue = createQueuer(\n * (item) => console.log('Processing', item),\n * { started: true, wait: 1000 },\n * (state) => ({\n * executionCount: state.executionCount,\n * rejectionCount: state.rejectionCount\n * })\n * );\n *\n * // Add items to process - they'll be handled automatically\n * queue.addItem('task1');\n * queue.addItem('task2');\n *\n * // Control the scheduler\n * queue.stop(); // Pause processing\n * queue.start(); // Resume processing\n *\n * // Access the selected state (will be empty object {} unless selector provided)\n * const { items, isRunning } = queue.state();\n * ```\n */\nexport function createQueuer<TValue, TSelected = {}>(\n fn: (item: TValue) => void,\n options: QueuerOptions<TValue> = {},\n selector: (state: QueuerState<TValue>) => TSelected = () => ({}) as TSelected,\n): SolidQueuer<TValue, TSelected> {\n const mergedOptions = {\n ...useDefaultPacerOptions().queuer,\n ...options,\n } as QueuerOptions<TValue>\n\n const queuer = new Queuer(fn, mergedOptions) as unknown as SolidQueuer<\n TValue,\n TSelected\n >\n\n queuer.Subscribe = function Subscribe<TSelected>(props: {\n selector: (state: QueuerState<TValue>) => TSelected\n children: ((state: Accessor<TSelected>) => JSX.Element) | JSX.Element\n }) {\n const selected = useStore(queuer.store, props.selector)\n\n return typeof props.children === 'function'\n ? props.children(selected)\n : props.children\n }\n\n const state = useStore(queuer.store, selector)\n\n return {\n ...queuer,\n state,\n } as SolidQueuer<TValue, TSelected> // omit `store` in favor of `state`\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkIA,SAAgB,aACd,IACA,UAAiC,EAAE,EACnC,kBAA6D,EAAE,GAC/B;CAMhC,MAAM,SAAS,IAAIA,8BAAO,IALJ;EACpB,GAAGC,8CAAwB,CAAC;EAC5B,GAAG;EACJ,CAE2C;AAK5C,QAAO,YAAY,SAAS,UAAqB,OAG9C;EACD,MAAM,+CAAoB,OAAO,OAAO,MAAM,SAAS;AAEvD,SAAO,OAAO,MAAM,aAAa,aAC7B,MAAM,SAAS,SAAS,GACxB,MAAM;;CAGZ,MAAM,4CAAiB,OAAO,OAAO,SAAS;AAE9C,QAAO;EACL,GAAG;EACH;EACD"}