Skip to content
Source
Sign inSign up
TanStack/pacer
Open History to see the last commit

createQueuedState.md

77 lines2.3 KB

1---
2id: createQueuedState
3title: createQueuedState
4---
5​
6```ts
7function createQueuedState<TValue, TSelected>(
8 host,
9 fn,
10 options?,
11 selector?): [() => TValue[], (item, position?, runOnItemsChange?) => boolean, LitQueuer<TValue, TSelected>];
12```
13​
14Defined in: [queuer/createQueuedState.ts:35](https://github.com/TanStack/pacer/blob/main/packages/lit-pacer/src/queuer/createQueuedState.ts#L35)
15​
16Exposes pending queue items together with the queue that processes them.
17​
18Retains accepted items until processing. Ordering, capacity, wait, and started options follow the underlying queue.
19​
20## Return value
21​
22Returns [itemsAccessor, addItem, queue]. Call itemsAccessor() to read pending items.
23​
24## State and ownership
25​
26Items are selected by default. A custom selector must retain items and may add other state fields. The returned collection contains pending items; async active items are separate.
27​
28Pass the owning ReactiveControllerHost first. Host updates refresh options. Disconnecting runs cleanup; reconnecting restores subscriptions to the same utility.
29Options accept an object with top-level getters or an options factory. Function-valued core options remain callbacks. Local options override provider defaults without replacing the utility or its pending work.
30onUnmount replaces default cleanup and receives the utility instance. A custom callback must perform every needed cancel, stop, or abort action.
31​
32## Type Parameters
33​
34### TValue
35​
36`TValue`
37​
38### TSelected
39​
40`TSelected` *extends* `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\> = `Pick`\<`QueuerState`\<`TValue`\>, `"items"`\>
41​
42## Parameters
43​
44### host
45​
46`ReactiveControllerHost`
47​
48### fn
49​
50(`item`) => `void`
51​
52### options?
53​
54[`LitPacerOptions`](../type-aliases/LitPacerOptions.md)\<[`LitQueuerOptions`](../interfaces/LitQueuerOptions.md)\<`TValue`, `TSelected`\>\> = `{}`
55​
56### selector?
57​
58(`state`) => `TSelected`
59​
60## Returns
61​
62\[() => `TValue`[], (`item`, `position?`, `runOnItemsChange?`) => `boolean`, [`LitQueuer`](../interfaces/LitQueuer.md)\<`TValue`, `TSelected`\>\]
63​
64## Example
65​
66```ts
67import { createQueuedState } from '@tanstack/lit-pacer'
68​
69// In a LitElement constructor:
70const [items, addItem, queue] = createQueuedState(this, (item: number) => { console.log(item) }, { wait: 500 })
71addItem(1)
72console.log(items())
73```
74​
75## See
76​
77createQueuer