Open History to see the last commit
1import {
2 InjectionToken,
3 assertInInjectionContext,
4 inject,
5 signal,
6} from '@angular/core'
7import type { Provider, Signal } from '@angular/core'
8β
9/**
10 * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`
11 */
12const IS_RESTORING = new InjectionToken('', {
13 factory: () => signal(false).asReadonly(),
14})
15β
16/**
17 * Injects a signal that tracks whether a restore (e.g. from a persisted client, wired up via
18 * `withPersistQueryClient`) is currently in progress. `injectQuery` and friends also check this internally
19 * to avoid race conditions between the restore and initializing queries.
20 * @returns A readonly `Signal<boolean>` β `true` while a restore is in progress, `false` otherwise (the
21 * default when no persistence integration is registered).
22 */
23export function injectIsRestoring() {
24 if (typeof ngDevMode === 'undefined' || ngDevMode) {
25 assertInInjectionContext(injectIsRestoring)
26 }
27 return inject(IS_RESTORING)
28}
29β
30/**
31 * Supplies injector-scoped restoration state to the Angular Query integrations.
32 * The factory runs once in Angular's injection context.
33 * @internal
34 * @param isRestoringFactory - Produces the restoration signal for this injector.
35 * @returns The provider that makes the restoration state injectable.
36 */
37export function provideIsRestoring(
38 isRestoringFactory: () => Signal<boolean>,
39): Provider {
40 return {
41 provide: IS_RESTORING,
42 useFactory: isRestoringFactory,
43 }
44}