-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Created isRestoring injection token and provider - handled restoration phase in create-base-query.ts - handled restoration phase in inject-queries.ts
- Loading branch information
1 parent
436422c
commit a358520
Showing
4 changed files
with
89 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
packages/angular-query-experimental/src/inject-is-restoring.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { InjectionToken, computed, inject } from '@angular/core' | ||
import { assertInjector } from './util/assert-injector/assert-injector' | ||
import type { Injector, Provider, Signal } from '@angular/core' | ||
|
||
const IsRestoring = new InjectionToken<Signal<boolean>>('IsRestoring') | ||
|
||
/** | ||
* Injects a signal that tracks whether a restore is currently in progress. {@link injectQuery} and friends also check this internally to avoid race conditions between the restore and mounting queries. | ||
* @param injector - The Angular injector to use. | ||
* @returns signal with boolean that indicates whether a restore is in progress. | ||
* @public | ||
*/ | ||
export function injectIsRestoring(injector?: Injector): Signal<boolean> { | ||
return assertInjector( | ||
injectIsRestoring, | ||
injector, | ||
() => inject(IsRestoring, { optional: true }) ?? computed(() => false), | ||
) | ||
} | ||
|
||
/** | ||
* Used by angular query persist client plugin to provide the signal that tracks the restore state | ||
* @param isRestoring - a readonly signal that returns a boolean | ||
* @returns Provider for the `isRestoring` signal | ||
* @public | ||
*/ | ||
export function provideIsRestoring(isRestoring: Signal<boolean>): Provider { | ||
return { | ||
provide: IsRestoring, | ||
useValue: isRestoring, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters