Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/big-jobs-call.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@tanstack/angular-pacer': minor
---

injectQueuedValue returns queued value instead of array
26 changes: 14 additions & 12 deletions docs/framework/angular/reference/functions/injectQueuedValue.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ title: injectQueuedValue
function injectQueuedValue<TValue, TSelected>(
value,
options?,
selector?): QueuedSignal<TValue, TSelected>;
selector?): QueuedValueSignal<TValue, TSelected>;
```

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:31](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L31)
Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:38](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L38)

An Angular function that creates a queued value that processes state changes in order with an optional delay.
This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.
Expand All @@ -23,9 +23,10 @@ The queued value will process changes in the order they are received, with optio
processing each change. This is useful for handling state updates that need to be processed
in a specific order, like animations or sequential UI updates.

The function returns a tuple containing:
- A Signal that provides the current queued value
- The queuer instance with control methods
The function returns a callable object containing:
- `queued()`: A signal-like function that provides the current queued value
- `queued.addItem(...)`: A method to enqueue additional values
- `queued.queuer`: The queuer instance with control methods and state

### Type Parameters

Expand Down Expand Up @@ -53,7 +54,7 @@ The function returns a tuple containing:

### Returns

[`QueuedSignal`](../interfaces/QueuedSignal.md)\<`TValue`, `TSelected`\>
[`QueuedValueSignal`](../interfaces/QueuedValueSignal.md)\<`TValue`, `TSelected`\>

### Example

Expand All @@ -75,10 +76,10 @@ function injectQueuedValue<TValue, TSelected>(
value,
initialValue,
options?,
selector?): QueuedSignal<TValue, TSelected>;
selector?): QueuedValueSignal<TValue, TSelected>;
```

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:42](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L42)
Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:49](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L49)

An Angular function that creates a queued value that processes state changes in order with an optional delay.
This function uses injectQueuedSignal internally to manage a queue of state changes and apply them sequentially.
Expand All @@ -87,9 +88,10 @@ The queued value will process changes in the order they are received, with optio
processing each change. This is useful for handling state updates that need to be processed
in a specific order, like animations or sequential UI updates.

The function returns a tuple containing:
- A Signal that provides the current queued value
- The queuer instance with control methods
The function returns a callable object containing:
- `queued()`: A signal-like function that provides the current queued value
- `queued.addItem(...)`: A method to enqueue additional values
- `queued.queuer`: The queuer instance with control methods and state

### Type Parameters

Expand Down Expand Up @@ -121,7 +123,7 @@ The function returns a tuple containing:

### Returns

[`QueuedSignal`](../interfaces/QueuedSignal.md)\<`TValue`, `TSelected`\>
[`QueuedValueSignal`](../interfaces/QueuedValueSignal.md)\<`TValue`, `TSelected`\>

### Example

Expand Down
1 change: 1 addition & 0 deletions docs/framework/angular/reference/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ title: "@tanstack/angular-pacer"
- [AsyncQueuedSignal](interfaces/AsyncQueuedSignal.md)
- [DebouncedSignal](interfaces/DebouncedSignal.md)
- [QueuedSignal](interfaces/QueuedSignal.md)
- [QueuedValueSignal](interfaces/QueuedValueSignal.md)
- [RateLimitedSignal](interfaces/RateLimitedSignal.md)
- [ThrottledSignal](interfaces/ThrottledSignal.md)

Expand Down
10 changes: 5 additions & 5 deletions docs/framework/angular/reference/interfaces/AsyncQueuedSignal.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Defined in: [angular-pacer/src/async-queuer/injectAsyncQueuedSignal.ts:10](https
### addItem()

```ts
addItem: (item, position?, runOnItemsChange?) => boolean;
addItem: (item, position, runOnItemsChange) => boolean;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Implementation (defaulted params) ==="
sed -n '470,477p' packages/pacer/src/async-queuer.ts
sed -n '9,15p' packages/angular-pacer/src/async-queuer/injectAsyncQueuedSignal.ts

echo
echo "=== Current docs (required params) ==="
rg -n -C2 'addItem: \(item, position, runOnItemsChange\) => boolean;|##### position\??|##### runOnItemsChange\??' \
  docs/framework/angular/reference/interfaces/AsyncQueuedSignal.md

Repository: TanStack/pacer

Length of output: 780


Mark position and runOnItemsChange parameters as optional in the addItem type signature and parameter documentation sections.

Line 36 and lines 50-56 should use the optional parameter notation (?) to match the default values in the implementation (packages/pacer/src/async-queuer.ts).

Suggested fix
-addItem: (item, position, runOnItemsChange) => boolean;
+addItem: (item, position?, runOnItemsChange?) => boolean;

-##### position
+##### position?

-##### runOnItemsChange
+##### runOnItemsChange?
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/angular/reference/interfaces/AsyncQueuedSignal.md` at line 36,
The addItem signature in the AsyncQueuedSignal interface should mark the
position and runOnItemsChange parameters as optional to match the
implementation; update the type signature for addItem to use position? and
runOnItemsChange? and update the corresponding parameter documentation entries
for position and runOnItemsChange in the AsyncQueuedSignal doc block so they
indicate optionality and align with packages/pacer/src/async-queuer.ts behavior.

```

Defined in: [angular-pacer/src/async-queuer/injectAsyncQueuedSignal.ts:11](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/async-queuer/injectAsyncQueuedSignal.ts#L11)
Expand All @@ -47,13 +47,13 @@ Items can be inserted based on priority or at the front/back depending on config

`TValue`

##### position?
##### position

`QueuePosition`
`QueuePosition` = `...`

##### runOnItemsChange?
##### runOnItemsChange

`boolean`
`boolean` = `true`

#### Returns

Expand Down
10 changes: 5 additions & 5 deletions docs/framework/angular/reference/interfaces/QueuedSignal.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Defined in: [angular-pacer/src/queuer/injectQueuedSignal.ts:7](https://github.co
### addItem()

```ts
addItem: (item, position?, runOnItemsChange?) => boolean;
addItem: (item, position, runOnItemsChange) => boolean;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Implementation (defaulted params) ==="
sed -n '401,408p' packages/pacer/src/queuer.ts
sed -n '6,12p' packages/angular-pacer/src/queuer/injectQueuedSignal.ts

echo
echo "=== Current docs (required params) ==="
rg -n -C2 'addItem: \(item, position, runOnItemsChange\) => boolean;|##### position\??|##### runOnItemsChange\??' \
  docs/framework/angular/reference/interfaces/QueuedSignal.md

Repository: TanStack/pacer

Length of output: 765


Update TypeScript signature and parameter headers to reflect optional parameters with defaults.

Line 36 documents addItem parameters as required, but the implementation in packages/pacer/src/queuer.ts defines defaults for both position and runOnItemsChange. The type signature should mark these as optional.

Suggested doc correction
-addItem: (item, position, runOnItemsChange) => boolean;
+addItem: (item, position?, runOnItemsChange?) => boolean;

-##### position
+##### position?

-##### runOnItemsChange
+##### runOnItemsChange?

Also applies to: lines 58-64

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/angular/reference/interfaces/QueuedSignal.md` at line 36,
Update the documented TypeScript signatures in the QueuedSignal interface to
mark parameters with defaults as optional: change addItem's signature to reflect
that position and runOnItemsChange are optional (with defaults coming from
packages/pacer/src/queuer.ts) and update the parameter headers/descriptions
accordingly; apply the same optional-parameter adjustments to the other
documented methods referenced around lines 58-64 so the docs match the
implementation in queuer.ts and clearly state default values for those optional
parameters.

```

Defined in: [angular-pacer/src/queuer/injectQueuedSignal.ts:8](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedSignal.ts#L8)
Expand All @@ -55,13 +55,13 @@ queuer.addItem('task2', 'front');

`TValue`

##### position?
##### position

`QueuePosition`
`QueuePosition` = `...`

##### runOnItemsChange?
##### runOnItemsChange

`boolean`
`boolean` = `true`

#### Returns

Expand Down
78 changes: 78 additions & 0 deletions docs/framework/angular/reference/interfaces/QueuedValueSignal.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
id: QueuedValueSignal
title: QueuedValueSignal
---

# Interface: QueuedValueSignal()\<TValue, TSelected\>

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:7](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L7)

## Type Parameters

### TValue

`TValue`

### TSelected

`TSelected` = \{
\}

```ts
QueuedValueSignal(): TValue;
```

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:8](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L8)

## Returns

`TValue`

## Properties

### addItem()

```ts
addItem: (item, position, runOnItemsChange) => boolean;
```

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:9](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L9)

Adds an item to the queue. If the queue is full, the item is rejected and onReject is called.
Items can be inserted based on priority or at the front/back depending on configuration.

Returns true if the item was added, false if the queue is full.

Example usage:
```ts
queuer.addItem('task');
queuer.addItem('task2', 'front');
```
Comment on lines +46 to +50
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

addItem example uses the wrong receiver name.

This interface documents QueuedValueSignal, so the example should call queued.addItem(...), not queuer.addItem(...), to avoid API confusion.

✏️ Suggested doc fix
 Example usage:
 ```ts
-queuer.addItem('task');
-queuer.addItem('task2', 'front');
+queued.addItem('task')
+queued.addItem('task2', 'front')
</details>

<!-- suggestion_start -->

<details>
<summary>📝 Committable suggestion</summary>

> ‼️ **IMPORTANT**
> Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

```suggestion
Example usage:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@docs/framework/angular/reference/interfaces/QueuedValueSignal.md` around
lines 46 - 50, The example under the QueuedValueSignal interface uses the wrong
receiver name; update the usage examples to call queued.addItem(...) instead of
queuer.addItem(...). Locate the example block showing addItem and replace calls
to queuer.addItem with queued.addItem so the documented API (QueuedValueSignal
and its addItem method) matches actual usage.


#### Parameters

##### item

`TValue`

##### position

`QueuePosition` = `...`

##### runOnItemsChange

`boolean` = `true`

#### Returns

`boolean`

***

### queuer

```ts
queuer: AngularQueuer<TValue, TSelected>;
```

Defined in: [angular-pacer/src/queuer/injectQueuedValue.ts:10](https://github.com/TanStack/pacer/blob/main/packages/angular-pacer/src/queuer/injectQueuedValue.ts#L10)
2 changes: 1 addition & 1 deletion examples/angular/injectQueuedValue/src/app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ <h1>injectQueuedValue</h1>

<p>Source (instant): {{ source() }}</p>
<p>Value (queued): {{ queued() }}</p>
<p>Queue length: {{ queued().length }}</p>
<p>Queue length: {{ queued.queuer.state().items.length }}</p>

<button (click)="enqueueRandom()">Enqueue random</button>
<button (click)="clear()">Clear</button>
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectQueuedValue/src/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class App {
protected readonly source = signal('')

// A queued value: changes are applied in-order, with an optional delay between items.
// `value()` is the current processed value, and `items()` exposes the pending queue.
// `queued()` is the current processed value, and `queued.queuer.state().items` exposes the pending queue.
protected readonly queued = injectQueuedValue(this.source, { wait: 500 }, (state) => ({
items: state.items,
}))
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/injectQueuedValue/src/app/inputapp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { injectQueuedValue } from '@tanstack/angular-pacer'
<h1>NG0950</h1>
<p>value: {{ value() }}</p>
<p>Value (queued): {{ queued() }}</p>
<p>Queue length: {{ queued().length }}</p>
<p>Queue length: {{ queued.queuer.state().items.length }}</p>
<button (click)="enqueueRandom()">Enqueue random</button>
`,
})
Expand Down
17 changes: 16 additions & 1 deletion packages/angular-pacer/eslint.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
// @ts-check

import rootConfig from '../../eslint.config.js'
import { fileURLToPath } from 'node:url'

const tsconfigRootDir = fileURLToPath(new URL('.', import.meta.url))

/** @type {import('eslint').Linter.Config[]} */
export default [...rootConfig]
export default [
...rootConfig,
{
name: 'angular-pacer/typescript-projects',
files: ['**/*.ts'],
languageOptions: {
parserOptions: {
project: ['./tsconfig.lib.json', './tsconfig.spec.json'],
tsconfigRootDir,
},
},
},
]
6 changes: 5 additions & 1 deletion packages/angular-pacer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,12 @@
"@tanstack/pacer": "workspace:*"
},
"devDependencies": {
"@analogjs/vite-plugin-angular": "^2.2.3",
"@analogjs/vitest-angular": "^2.2.3",
"@angular/compiler": "^21.1.4",
"@angular/core": "^21.1.4",
"@types/node": "^25.2.3"
"@types/node": "^25.2.3",
"jsdom": "^28.1.0"
},
"peerDependencies": {
"@angular/core": ">=17.0.0"
Expand Down
41 changes: 25 additions & 16 deletions packages/angular-pacer/src/queuer/injectQueuedValue.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { effect, linkedSignal, signal } from '@angular/core'
import { effect, linkedSignal, untracked } from '@angular/core'
import { injectQueuedSignal } from './injectQueuedSignal'
import type { QueuedSignal } from './injectQueuedSignal'
import type { Signal } from '@angular/core'
import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
import type { AngularQueuer } from './injectQueuer'

export interface QueuedValueSignal<TValue, TSelected = {}> {
(): TValue
addItem: AngularQueuer<TValue, TSelected>['addItem']
queuer: AngularQueuer<TValue, TSelected>
}

/**
* An Angular function that creates a queued value that processes state changes in order with an optional delay.
Expand All @@ -12,9 +18,10 @@ import type { QueuerOptions, QueuerState } from '@tanstack/pacer/queuer'
* processing each change. This is useful for handling state updates that need to be processed
* in a specific order, like animations or sequential UI updates.
*
* The function returns a tuple containing:
* - A Signal that provides the current queued value
* - The queuer instance with control methods
* The function returns a callable object containing:
* - `queued()`: A signal-like function that provides the current queued value
* - `queued.addItem(...)`: A method to enqueue additional values
* - `queued.queuer`: The queuer instance with control methods and state
*
* @example
* ```ts
Expand All @@ -38,7 +45,7 @@ export function injectQueuedValue<
value: Signal<TValue>,
options?: QueuerOptions<TValue>,
selector?: (state: QueuerState<TValue>) => TSelected,
): QueuedSignal<TValue, TSelected>
): QueuedValueSignal<TValue, TSelected>
export function injectQueuedValue<
TValue,
TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
Expand All @@ -50,7 +57,7 @@ export function injectQueuedValue<
initialValue: TValue,
options?: QueuerOptions<TValue>,
selector?: (state: QueuerState<TValue>) => TSelected,
): QueuedSignal<TValue, TSelected>
): QueuedValueSignal<TValue, TSelected>
export function injectQueuedValue<
TValue,
TSelected extends Pick<QueuerState<TValue>, 'items'> = Pick<
Expand All @@ -64,15 +71,11 @@ export function injectQueuedValue<
| QueuerOptions<TValue>
| ((state: QueuerState<TValue>) => TSelected),
maybeSelector?: (state: QueuerState<TValue>) => TSelected,
): QueuedSignal<TValue, TSelected> {
): QueuedValueSignal<TValue, TSelected> {
const hasSelector = typeof initialOptionsOrSelector === 'function'
const hasInitialValue =
(initialOptionsOrSelector !== undefined && !hasSelector) ||
maybeSelector !== undefined

const initialValue = hasInitialValue
? (initialValueOrOptions as TValue)
: value()
const initialOptions = hasInitialValue
? (initialOptionsOrSelector as QueuerOptions<TValue>)
: (initialValueOrOptions as QueuerOptions<TValue>)
Expand All @@ -82,8 +85,11 @@ export function injectQueuedValue<
| ((state: QueuerState<TValue>) => TSelected)
| undefined)

const linkedValue = linkedSignal(() => value())
const queuedValue = signal<TValue>(initialValue)
const queuedValue = linkedSignal<TValue>(() => {
return hasInitialValue
? (initialValueOrOptions as TValue)
: untracked(value)
})

const queued = injectQueuedSignal(
(item) => {
Expand All @@ -94,8 +100,11 @@ export function injectQueuedValue<
)

effect(() => {
queued.addItem(linkedValue())
queued.addItem(value())
})

return queued
return Object.assign(queuedValue, {
addItem: queued.addItem.bind(queued),
queuer: queued.queuer,
}) as QueuedValueSignal<TValue, TSelected>
}
Loading