-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular-query): support inject(QueryClient)
- Loading branch information
Showing
22 changed files
with
71 additions
and
298 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
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
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
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
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
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
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
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
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
29 changes: 12 additions & 17 deletions
29
packages/angular-query-experimental/src/inject-query-client.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 |
---|---|---|
@@ -1,27 +1,22 @@ | ||
import { createNoopInjectionToken } from './util/create-injection-token/create-injection-token' | ||
import type { QueryClient } from '@tanstack/query-core' | ||
|
||
const tokens = createNoopInjectionToken<QueryClient>('QueryClientToken') | ||
import { Injector, inject } from '@angular/core' | ||
import { QueryClient } from '@tanstack/query-core' | ||
import type { InjectOptions } from '@angular/core' | ||
|
||
/** | ||
* Injects the `QueryClient` instance into the component or service. | ||
* Injects a `QueryClient` instance and allows passing a custom injector. | ||
* | ||
* You can also use `inject(QueryClient)` if you don't need to provide a custom injector. | ||
* | ||
* **Example** | ||
* ```ts | ||
* const queryClient = injectQueryClient(); | ||
* ``` | ||
* @param injectOptions - Type of the options argument to inject and optionally a custom injector. | ||
* @returns The `QueryClient` instance. | ||
* @public | ||
*/ | ||
export const injectQueryClient = tokens[0] | ||
|
||
/** | ||
* Usually {@link provideTanStackQuery} is used once to set up TanStack Query and the | ||
* {@link https://tanstack.com/query/latest/docs/reference/QueryClient|QueryClient} | ||
* for the entire application. You can use `provideQueryClient` to provide a | ||
* different `QueryClient` instance for a part of the application. | ||
* @public | ||
*/ | ||
export const provideQueryClient = tokens[1] | ||
|
||
export const QUERY_CLIENT = tokens[2] | ||
export function injectQueryClient( | ||
injectOptions: InjectOptions & { injector?: Injector } = {}, | ||
) { | ||
return (injectOptions.injector ?? inject(Injector)).get(QueryClient) | ||
} |
Oops, something went wrong.