Lists and bulk actions
One mutation shared by every item of a list, called once per item. pendingInputs() lists the inputs of the calls still in flight: a spinner on each item being written, and pendingInputs().length for the progress of a bulk action. When the order of the writes matters, as when reordering a list, concurrency: 'queue' sends them one at a time. Source: seats · move to top
Lock seats
Click several seats in a row. A lock takes 4 s (an artificial delay); seat 6 is already taken.
Hand-written
- lockingSeats()
- —
- Safe to leave the page
- yes
Server
- Nothing yet.
rxMutation()
- pendingInputs()
- —
- Safe to leave the page
- yes
Server
- Nothing yet.
protected readonly lockSeat = rxMutation<number, number>({
mutationFn: (seat) => this.mutationServer.lockSeat(seat),
onSuccess: (seat) => this.mutationLocked.update((seats) => [...seats, seat]),
onError: (_error, seat) => this.mutationRefused.update((seats) => [...seats, seat]),
});@let state =
mutationLocked().includes(seat)
? 'locked'
: lockSeat.pendingInputs().includes(seat)
? 'locking'
: mutationRefused().includes(seat)
? 'refused'
: 'free';Move an item to the top
- Alpha
- Bravo
- Charlie
Click Charlie, then quickly Alpha. Charlie takes 1.2 s, the others 0.3 s (artificial delays).
Default (parallel)
- value(): latest call's response
- —
- server order
- Alpha, Bravo, Charlie
Charlie ends first, and value() doesn't match the server.
Server
- Nothing yet.
concurrency: 'queue'
- value(): latest call's response
- —
- server order
- Alpha, Bravo, Charlie
Alpha ends first, and value() matches the server.
Server
- Nothing yet.
protected readonly moveQueued = mutation<string, string[]>({
concurrency: 'queue',
mutationFn: (item, abortSignal) => this.queuedServer.moveToTop(item, abortSignal),
});