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

inject-is-restoring.ts

40 lines1.1 KB

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 readonly signal that is true while the persistence integration restores
18 * cached query data. Returns false when no restoration is in progress.
19 * @returns The current restoration state.
20 */
21export function injectIsRestoring() {
22 if (typeof ngDevMode === 'undefined' || ngDevMode) {
23 assertInInjectionContext(injectIsRestoring)
24 }
25 return inject(IS_RESTORING)
27​
28/**
29 * Supplies injector-scoped restoration state to the Angular Query integrations.
30 * The factory runs once in Angular's injection context.
31 * @internal
32 */
33export function provideIsRestoring(
34 isRestoringFactory: () => Signal<boolean>,
35): Provider {
36 return {
37 provide: IS_RESTORING,
38 useFactory: isRestoringFactory,
39 }