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

pending-tasks-compat.ts

28 lines880 Bytes

1import { InjectionToken, inject } from '@angular/core'
2import * as ng from '@angular/core'
3import { noop } from '@tanstack/query-core'
4​
5type PendingTasksCompat = { add: () => PendingTaskRef }
6​
7export type PendingTaskRef = () => void
8​
9export const PENDING_TASKS = new InjectionToken<PendingTasksCompat>(
10 'PENDING_TASKS',
11 {
12 factory: (): PendingTasksCompat => {
13 // Access via Reflect so bundlers stay quiet when the token is absent (Angular < 19).
14 const token = Reflect.get(ng, 'PendingTasks') as unknown as
15 | Parameters<typeof inject>[0]
16 | undefined
17​
18 const svc: PendingTasksCompat | null = token
19 ? (inject(token, { optional: true }) as PendingTasksCompat | null)
20 : null
21​
22 // Without PendingTasks we fall back to a stable no-op shim.
23 return {
24 add: svc ? () => svc.add() : () => noop,
25 }
26 },
27 },