@tanstack/angular-query-experimental 5.102.8 → 5.103.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/infinite-query-options.d.ts +193 -12
- package/infinite-query-options.mjs.map +1 -1
- package/inject-infinite-query.d.ts +189 -11
- package/inject-infinite-query.mjs.map +1 -1
- package/inject-is-fetching.d.ts +37 -5
- package/inject-is-fetching.mjs.map +1 -1
- package/inject-is-mutating.d.ts +20 -4
- package/inject-is-mutating.mjs.map +1 -1
- package/inject-is-restoring.d.ts +11 -6
- package/inject-is-restoring.mjs.map +1 -1
- package/inject-mutation-state.d.ts +55 -4
- package/inject-mutation-state.mjs.map +1 -1
- package/inject-mutation.d.ts +133 -4
- package/inject-mutation.mjs.map +1 -1
- package/inject-queries.d.ts +153 -4
- package/inject-queries.mjs.map +1 -1
- package/inject-query.d.ts +100 -82
- package/inject-query.mjs.map +1 -1
- package/mutation-options.d.ts +65 -20
- package/mutation-options.mjs.map +1 -1
- package/package.json +3 -3
- package/providers.d.ts +40 -43
- package/providers.mjs.map +1 -1
- package/query-options.d.ts +183 -40
- package/query-options.mjs.map +1 -1
- package/types.d.ts +156 -0
|
@@ -1,35 +1,216 @@
|
|
|
1
1
|
import { DefaultError, InfiniteData, InitialDataFunction, NonUndefinedGuard, OmitKeyof, QueryKey, QueryKeyWithDataTag, SkipToken } from '@tanstack/query-core';
|
|
2
2
|
import { CreateInfiniteQueryOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`
|
|
5
|
+
* may be `undefined` while the query is `pending`.
|
|
6
|
+
*
|
|
7
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
8
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
9
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
10
|
+
* the shape of all fetched pages plus their page params.
|
|
11
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
12
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
13
|
+
*/
|
|
3
14
|
export type UndefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
15
|
+
/**
|
|
16
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
17
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
18
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
19
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
20
|
+
* cache.
|
|
21
|
+
*/
|
|
4
22
|
initialData?: undefined | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | InitialDataFunction<NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>>;
|
|
5
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and
|
|
26
|
+
* `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be
|
|
27
|
+
* `skipToken`.
|
|
28
|
+
*
|
|
29
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
30
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
31
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
32
|
+
* the shape of all fetched pages plus their page params.
|
|
33
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
34
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
35
|
+
*/
|
|
6
36
|
export type UnusedSkipTokenInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = OmitKeyof<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, 'queryFn'> & {
|
|
37
|
+
/**
|
|
38
|
+
* `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If
|
|
39
|
+
* you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a
|
|
40
|
+
* fetch that fails with "Missing queryFn" unless `enabled` is `false` or a default query function has been
|
|
41
|
+
* defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.
|
|
42
|
+
*/
|
|
7
43
|
queryFn?: Exclude<CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>['queryFn'], SkipToken | undefined>;
|
|
8
44
|
};
|
|
45
|
+
/**
|
|
46
|
+
* The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is
|
|
47
|
+
* never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
48
|
+
*
|
|
49
|
+
* @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.
|
|
50
|
+
* @template TError - The type of errors your `queryFn` may throw.
|
|
51
|
+
* @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,
|
|
52
|
+
* the shape of all fetched pages plus their page params.
|
|
53
|
+
* @template TQueryKey - The type of your `queryKey`.
|
|
54
|
+
* @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.
|
|
55
|
+
*/
|
|
9
56
|
export type DefinedInitialDataInfiniteOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CreateInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & {
|
|
57
|
+
/**
|
|
58
|
+
* If set, this value will be used as the initial data for the query cache (as long as the query hasn't been
|
|
59
|
+
* created or cached yet). If set to a function, the function will be called **once** during the shared/root
|
|
60
|
+
* query initialization, and be expected to synchronously return the initial data. Initial data is
|
|
61
|
+
* considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the
|
|
62
|
+
* cache.
|
|
63
|
+
*/
|
|
10
64
|
initialData: NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>> | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>) | undefined;
|
|
11
65
|
};
|
|
12
66
|
/**
|
|
13
|
-
*
|
|
67
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to
|
|
68
|
+
* `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
|
|
69
|
+
* `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
|
|
70
|
+
* for.
|
|
71
|
+
*
|
|
72
|
+
* This overload is selected when `initialData` is set.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
75
|
+
* @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
76
|
+
* `injectInfiniteQuery`, with `initialData` set.
|
|
77
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
78
|
+
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
79
|
+
* automatically as the user scrolls.
|
|
14
80
|
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```angular-ts
|
|
83
|
+
* import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
|
|
84
|
+
*
|
|
85
|
+
* export const projectsOptions = infiniteQueryOptions({
|
|
86
|
+
* queryKey: ['projects'],
|
|
87
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
88
|
+
* initialPageParam: 0,
|
|
89
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
90
|
+
* initialData: { pages: [], pageParams: [] },
|
|
91
|
+
* })
|
|
92
|
+
*
|
|
93
|
+
* @Component({
|
|
94
|
+
* selector: 'projects',
|
|
95
|
+
* template: `
|
|
96
|
+
* <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a
|
|
97
|
+
* refetch fails, so the list stays visible alongside the error. -->
|
|
98
|
+
* <ul>
|
|
99
|
+
* @for (page of projectsQuery.data().pages; track $index) {
|
|
100
|
+
* @for (project of page.projects; track project.id) {
|
|
101
|
+
* <li>{{ project.name }}</li>
|
|
102
|
+
* }
|
|
103
|
+
* }
|
|
104
|
+
* </ul>
|
|
105
|
+
* `,
|
|
106
|
+
* })
|
|
107
|
+
* export class Projects {
|
|
108
|
+
* readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)
|
|
109
|
+
* }
|
|
110
|
+
* ```
|
|
18
111
|
*/
|
|
19
112
|
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
20
113
|
/**
|
|
21
|
-
*
|
|
114
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to
|
|
115
|
+
* `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
|
|
116
|
+
* `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
|
|
117
|
+
* for.
|
|
118
|
+
*
|
|
119
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
120
|
+
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or
|
|
121
|
+
* automatically as the user scrolls.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
125
|
+
* ```angular-ts
|
|
126
|
+
* import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
|
|
127
|
+
*
|
|
128
|
+
* export const commentsOptions = (postId: string) =>
|
|
129
|
+
* infiniteQueryOptions({
|
|
130
|
+
* queryKey: ['post', postId, 'comments'],
|
|
131
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
132
|
+
* initialPageParam: 0,
|
|
133
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
134
|
+
* })
|
|
22
135
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
136
|
+
* @Component({
|
|
137
|
+
* selector: 'comments',
|
|
138
|
+
* template: `
|
|
139
|
+
* @if (commentsQuery.isPending()) {
|
|
140
|
+
* Loading...
|
|
141
|
+
* } @else if (commentsQuery.isError()) {
|
|
142
|
+
* <span>Error: {{ commentsQuery.error()?.message }}</span>
|
|
143
|
+
* } @else {
|
|
144
|
+
* <ul>
|
|
145
|
+
* @for (page of commentsQuery.data().pages; track $index) {
|
|
146
|
+
* @for (comment of page.comments; track comment.id) {
|
|
147
|
+
* <li>{{ comment.text }}</li>
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
* </ul>
|
|
151
|
+
* }
|
|
152
|
+
* `,
|
|
153
|
+
* })
|
|
154
|
+
* export class Comments {
|
|
155
|
+
* readonly postId = signal('1')
|
|
156
|
+
* readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*
|
|
160
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
161
|
+
* @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to
|
|
162
|
+
* `injectInfiniteQuery`.
|
|
26
163
|
*/
|
|
27
164
|
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UnusedSkipTokenInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
28
165
|
/**
|
|
29
|
-
*
|
|
166
|
+
* You can generally pass everything to `infiniteQueryOptions` that you can also pass to
|
|
167
|
+
* `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as
|
|
168
|
+
* `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options
|
|
169
|
+
* for.
|
|
170
|
+
*
|
|
171
|
+
* @returns The same options object, typed so that `queryKey` carries the inferred data type.
|
|
172
|
+
* @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or
|
|
173
|
+
* automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.
|
|
174
|
+
*
|
|
175
|
+
* @example
|
|
176
|
+
* A parameterized factory, so the same options object can be reused per `postId`:
|
|
177
|
+
* ```angular-ts
|
|
178
|
+
* import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'
|
|
179
|
+
*
|
|
180
|
+
* export const commentsOptions = (postId: string) =>
|
|
181
|
+
* infiniteQueryOptions({
|
|
182
|
+
* queryKey: ['post', postId, 'comments'],
|
|
183
|
+
* queryFn: ({ pageParam }) => fetchComments(postId, pageParam),
|
|
184
|
+
* initialPageParam: 0,
|
|
185
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
186
|
+
* })
|
|
187
|
+
*
|
|
188
|
+
* @Component({
|
|
189
|
+
* selector: 'comments',
|
|
190
|
+
* template: `
|
|
191
|
+
* @if (commentsQuery.isPending()) {
|
|
192
|
+
* Loading...
|
|
193
|
+
* } @else if (commentsQuery.isError()) {
|
|
194
|
+
* <span>Error: {{ commentsQuery.error()?.message }}</span>
|
|
195
|
+
* } @else {
|
|
196
|
+
* <ul>
|
|
197
|
+
* @for (page of commentsQuery.data().pages; track $index) {
|
|
198
|
+
* @for (comment of page.comments; track comment.id) {
|
|
199
|
+
* <li>{{ comment.text }}</li>
|
|
200
|
+
* }
|
|
201
|
+
* }
|
|
202
|
+
* </ul>
|
|
203
|
+
* }
|
|
204
|
+
* `,
|
|
205
|
+
* })
|
|
206
|
+
* export class Comments {
|
|
207
|
+
* readonly postId = signal('1')
|
|
208
|
+
* readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))
|
|
209
|
+
* }
|
|
210
|
+
* ```
|
|
30
211
|
*
|
|
31
|
-
*
|
|
32
|
-
* @param options - The
|
|
33
|
-
*
|
|
212
|
+
* @see {@link injectInfiniteQuery} to run an infinite query with these options.
|
|
213
|
+
* @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to
|
|
214
|
+
* `injectInfiniteQuery`.
|
|
34
215
|
*/
|
|
35
216
|
export declare function infiniteQueryOptions<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(options: UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam> & QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\n/**\n * Allows sharing and re-using infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * Allows sharing and re-using infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * Allows sharing and re-using infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * Allows sharing and re-using infinite query options in a type-safe way.\n *\n * The `queryKey` will be tagged with the type from `queryFn`.\n * @param options - The infinite query options to tag with the type from `queryFn`.\n * @returns The tagged infinite query options.\n */\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AAiLO,SAAS,qBAAqB,SAAkB;AACrD,SAAO;AACT;"}
|
|
1
|
+
{"version":3,"file":"infinite-query-options.mjs","sources":["../src/infinite-query-options.ts"],"sourcesContent":["import type {\n DefaultError,\n InfiniteData,\n InitialDataFunction,\n NonUndefinedGuard,\n OmitKeyof,\n QueryKey,\n QueryKeyWithDataTag,\n SkipToken,\n} from '@tanstack/query-core'\nimport type { CreateInfiniteQueryOptions } from './types'\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set — `data`\n * may be `undefined` while the query is `pending`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData?:\n | undefined\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | InitialDataFunction<\n NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when no `initialData` is set and\n * `queryFn` is not `skipToken` — same as {@link UndefinedInitialDataInfiniteOptions}, but `queryFn` may not be\n * `skipToken`.\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = OmitKeyof<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n 'queryFn'\n> & {\n /**\n * `skipToken` is not allowed as a value here — this overload is selected when no `initialData` is set. If\n * you don't intend to run the query yet, set `enabled: false` — omitting `queryFn` alone still triggers a\n * fetch that fails with \"Missing queryFn\" unless `enabled` is `false` or a default query function has been\n * defined. A default query function only supplies `queryFn`; it doesn't defer the fetch on its own.\n */\n queryFn?: Exclude<\n CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >['queryFn'],\n SkipToken | undefined\n >\n}\n\n/**\n * The options accepted by the `infiniteQueryOptions` overload selected when `initialData` is set — `data` is\n * never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @template TQueryFnData - The type of a single page, as your `queryFn` resolves it.\n * @template TError - The type of errors your `queryFn` may throw.\n * @template TData - The type `data` ends up as after `select` runs — defaults to `InfiniteData<TQueryFnData>`,\n * the shape of all fetched pages plus their page params.\n * @template TQueryKey - The type of your `queryKey`.\n * @template TPageParam - The type of the parameter passed to `queryFn` to fetch a given page.\n */\nexport type DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> & {\n /**\n * If set, this value will be used as the initial data for the query cache (as long as the query hasn't been\n * created or cached yet). If set to a function, the function will be called **once** during the shared/root\n * query initialization, and be expected to synchronously return the initial data. Initial data is\n * considered stale by default unless a `staleTime` has been set. `initialData` **is persisted** to the\n * cache.\n */\n initialData:\n | NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>\n | (() => NonUndefinedGuard<InfiniteData<TQueryFnData, TPageParam>>)\n | undefined\n}\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * This overload is selected when `initialData` is set.\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link DefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`, with `initialData` set.\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const projectsOptions = infiniteQueryOptions({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * })\n *\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => projectsOptions)\n * }\n * ```\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages, from a button click or\n * automatically as the user scrolls.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UnusedSkipTokenInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UnusedSkipTokenInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\n/**\n * You can generally pass everything to `infiniteQueryOptions` that you can also pass to\n * `injectInfiniteQuery`. These options can be shared across functions and imperative APIs such as\n * `queryClient.fetchInfiniteQuery`. `options.queryKey` is required and is the query key to generate options\n * for.\n *\n * @returns The same options object, typed so that `queryKey` carries the inferred data type.\n * @remarks See {@link injectInfiniteQuery} for examples that fetch further pages (from a button click or\n * automatically as the user scrolls) and that use `skipToken` to disable the query until `postId` is set.\n *\n * @example\n * A parameterized factory, so the same options object can be reused per `postId`:\n * ```angular-ts\n * import { infiniteQueryOptions, injectInfiniteQuery } from '@tanstack/angular-query-experimental'\n *\n * export const commentsOptions = (postId: string) =>\n * infiniteQueryOptions({\n * queryKey: ['post', postId, 'comments'],\n * queryFn: ({ pageParam }) => fetchComments(postId, pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * })\n *\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal('1')\n * readonly commentsQuery = injectInfiniteQuery(() => commentsOptions(this.postId()))\n * }\n * ```\n *\n * @see {@link injectInfiniteQuery} to run an infinite query with these options.\n * @param options - The {@link UndefinedInitialDataInfiniteOptions} to use — everything you can pass to\n * `injectInfiniteQuery`.\n */\nexport function infiniteQueryOptions<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n> &\n QueryKeyWithDataTag<TQueryKey, InfiniteData<TQueryFnData>, TError>\n\nexport function infiniteQueryOptions(options: unknown) {\n return options\n}\n"],"names":[],"mappings":"AA+VO,SAAS,qBAAqB,SAAkB;AACrD,SAAO;AACT;"}
|
|
@@ -11,25 +11,203 @@ export interface InjectInfiniteQueryOptions {
|
|
|
11
11
|
injector?: Injector;
|
|
12
12
|
}
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of
|
|
15
|
+
* `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can
|
|
16
|
+
* additively "load more" data onto an existing set of data, or "infinite scroll".
|
|
17
|
+
*
|
|
18
|
+
* This overload is selected when `initialData` is set on the options returned by `injectInfiniteQueryFn`,
|
|
19
|
+
* so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to include `undefined`).
|
|
20
|
+
*
|
|
21
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
22
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
23
|
+
* actions, or add conditions like `hasNextPage() && !isFetching()`.
|
|
24
|
+
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs
|
|
25
|
+
* like `queryClient.fetchInfiniteQuery`.
|
|
26
|
+
* @param injectInfiniteQueryFn - A function returning the {@link DefinedInitialDataInfiniteOptions} to use —
|
|
27
|
+
* everything you can pass to `injectInfiniteQuery`, with `initialData` set. Similar to `computed` from
|
|
28
|
+
* Angular, this function runs in the reactive context, so signals read inside it drive the query.
|
|
17
29
|
* @param options - Additional configuration.
|
|
18
|
-
* @returns The
|
|
30
|
+
* @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
|
31
|
+
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
|
|
32
|
+
* `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
33
|
+
* `InfiniteData<TQueryFnData>` shape.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```angular-ts
|
|
37
|
+
* @Component({
|
|
38
|
+
* selector: 'projects',
|
|
39
|
+
* template: `
|
|
40
|
+
* <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a
|
|
41
|
+
* refetch fails, so the list stays visible alongside the error. -->
|
|
42
|
+
* <ul>
|
|
43
|
+
* @for (page of projectsQuery.data().pages; track $index) {
|
|
44
|
+
* @for (project of page.projects; track project.id) {
|
|
45
|
+
* <li>{{ project.name }}</li>
|
|
46
|
+
* }
|
|
47
|
+
* }
|
|
48
|
+
* </ul>
|
|
49
|
+
* `,
|
|
50
|
+
* })
|
|
51
|
+
* export class Projects {
|
|
52
|
+
* readonly projectsQuery = injectInfiniteQuery(() => ({
|
|
53
|
+
* queryKey: ['projects'],
|
|
54
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
55
|
+
* initialPageParam: 0,
|
|
56
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
57
|
+
* initialData: { pages: [], pageParams: [] },
|
|
58
|
+
* }))
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
19
61
|
*/
|
|
20
62
|
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): DefinedCreateInfiniteQueryResult<TData, TError>;
|
|
21
63
|
/**
|
|
22
|
-
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a
|
|
23
|
-
* Infinite queries can additively "load more" data onto an existing set of data or
|
|
24
|
-
*
|
|
64
|
+
* Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a
|
|
65
|
+
* unique key. Infinite queries can additively "load more" data onto an existing set of data, or
|
|
66
|
+
* "infinite scroll".
|
|
67
|
+
*
|
|
68
|
+
* @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
|
|
69
|
+
* refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
|
|
70
|
+
* actions, or add conditions like `hasNextPage() && !isFetching()`. This is the only overload that accepts
|
|
71
|
+
* `queryFn: skipToken`, shown below.
|
|
72
|
+
* @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs
|
|
73
|
+
* like `queryClient.fetchInfiniteQuery`.
|
|
74
|
+
* @param injectInfiniteQueryFn - A function returning the {@link UndefinedInitialDataInfiniteOptions} to use
|
|
75
|
+
* — everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs
|
|
76
|
+
* in the reactive context, so signals read inside it drive the query.
|
|
25
77
|
* @param options - Additional configuration.
|
|
26
|
-
* @returns The
|
|
78
|
+
* @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
|
|
79
|
+
* `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
|
|
80
|
+
* `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
|
|
81
|
+
* `InfiniteData<TQueryFnData>` shape.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* Fetching the next page from a button click:
|
|
85
|
+
* ```angular-ts
|
|
86
|
+
* @Component({
|
|
87
|
+
* selector: 'projects-list',
|
|
88
|
+
* template: `
|
|
89
|
+
* <ul>
|
|
90
|
+
* @for (page of projectsQuery.data()?.pages; track $index) {
|
|
91
|
+
* @for (project of page.projects; track project.id) {
|
|
92
|
+
* <li>{{ project.name }}</li>
|
|
93
|
+
* }
|
|
94
|
+
* }
|
|
95
|
+
* </ul>
|
|
96
|
+
* <button
|
|
97
|
+
* [disabled]="!projectsQuery.hasNextPage() || projectsQuery.isFetching()"
|
|
98
|
+
* (click)="projectsQuery.fetchNextPage()"
|
|
99
|
+
* >
|
|
100
|
+
* Load More
|
|
101
|
+
* </button>
|
|
102
|
+
* `,
|
|
103
|
+
* })
|
|
104
|
+
* export class ProjectsList {
|
|
105
|
+
* readonly projectsQuery = injectInfiniteQuery(() => ({
|
|
106
|
+
* queryKey: ['projects'],
|
|
107
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
108
|
+
* initialPageParam: 0,
|
|
109
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
110
|
+
* }))
|
|
111
|
+
* }
|
|
112
|
+
* ```
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel
|
|
116
|
+
* element after the list:
|
|
117
|
+
* ```angular-ts
|
|
118
|
+
* @Component({
|
|
119
|
+
* selector: 'projects-list',
|
|
120
|
+
* template: `
|
|
121
|
+
* <ul>
|
|
122
|
+
* @for (page of projectsQuery.data()?.pages; track $index) {
|
|
123
|
+
* @for (project of page.projects; track project.id) {
|
|
124
|
+
* <li>{{ project.name }}</li>
|
|
125
|
+
* }
|
|
126
|
+
* }
|
|
127
|
+
* </ul>
|
|
128
|
+
* <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>
|
|
129
|
+
* `,
|
|
130
|
+
* })
|
|
131
|
+
* export class ProjectsList {
|
|
132
|
+
* readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')
|
|
133
|
+
*
|
|
134
|
+
* readonly projectsQuery = injectInfiniteQuery(() => ({
|
|
135
|
+
* queryKey: ['projects'],
|
|
136
|
+
* queryFn: ({ pageParam }) => fetchProjects(pageParam),
|
|
137
|
+
* initialPageParam: 0,
|
|
138
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
139
|
+
* }))
|
|
140
|
+
*
|
|
141
|
+
* constructor() {
|
|
142
|
+
* effect((onCleanup) => {
|
|
143
|
+
* const sentinel = this.sentinel()?.nativeElement
|
|
144
|
+
* if (
|
|
145
|
+
* sentinel == null ||
|
|
146
|
+
* !this.projectsQuery.hasNextPage() ||
|
|
147
|
+
* this.projectsQuery.isFetching()
|
|
148
|
+
* ) {
|
|
149
|
+
* return
|
|
150
|
+
* }
|
|
151
|
+
*
|
|
152
|
+
* const observer = new IntersectionObserver(([entry]) => {
|
|
153
|
+
* if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()
|
|
154
|
+
* })
|
|
155
|
+
* observer.observe(sentinel)
|
|
156
|
+
*
|
|
157
|
+
* onCleanup(() => observer.disconnect())
|
|
158
|
+
* })
|
|
159
|
+
* }
|
|
160
|
+
* }
|
|
161
|
+
* ```
|
|
162
|
+
*
|
|
163
|
+
* @example
|
|
164
|
+
* A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn` instead of
|
|
165
|
+
* setting `enabled: false`:
|
|
166
|
+
* ```angular-ts
|
|
167
|
+
* @Component({
|
|
168
|
+
* selector: 'comments',
|
|
169
|
+
* template: `
|
|
170
|
+
* @if (postId() == null) {
|
|
171
|
+
* Select a post
|
|
172
|
+
* } @else if (commentsQuery.isPending()) {
|
|
173
|
+
* Loading...
|
|
174
|
+
* } @else if (commentsQuery.isError()) {
|
|
175
|
+
* <span>Error: {{ commentsQuery.error()?.message }}</span>
|
|
176
|
+
* } @else {
|
|
177
|
+
* <ul>
|
|
178
|
+
* @for (page of commentsQuery.data().pages; track $index) {
|
|
179
|
+
* @for (comment of page.comments; track comment.id) {
|
|
180
|
+
* <li>{{ comment.text }}</li>
|
|
181
|
+
* }
|
|
182
|
+
* }
|
|
183
|
+
* </ul>
|
|
184
|
+
* }
|
|
185
|
+
* `,
|
|
186
|
+
* })
|
|
187
|
+
* export class Comments {
|
|
188
|
+
* readonly postId = signal<string | undefined>(undefined)
|
|
189
|
+
*
|
|
190
|
+
* readonly commentsQuery = injectInfiniteQuery(() => ({
|
|
191
|
+
* queryKey: ['post', this.postId(), 'comments'],
|
|
192
|
+
* queryFn:
|
|
193
|
+
* this.postId() != null
|
|
194
|
+
* ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)
|
|
195
|
+
* : skipToken,
|
|
196
|
+
* initialPageParam: 0,
|
|
197
|
+
* getNextPageParam: (lastPage) => lastPage.nextId,
|
|
198
|
+
* }))
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
27
201
|
*/
|
|
28
202
|
export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, options?: InjectInfiniteQueryOptions): CreateInfiniteQueryResult<TData, TError>;
|
|
29
203
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
204
|
+
* This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the
|
|
205
|
+
* `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site —
|
|
206
|
+
* useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided
|
|
207
|
+
* options.
|
|
208
|
+
*
|
|
209
|
+
* @param injectInfiniteQueryFn - A function that returns infinite query options. Similar to `computed` from
|
|
210
|
+
* Angular, this function runs in the reactive context, so signals read inside it drive the query.
|
|
33
211
|
* @param options - Additional configuration.
|
|
34
212
|
* @returns The infinite query result.
|
|
35
213
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-infinite-query.mjs","sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport {\n Injector,\n assertInInjectionContext,\n inject,\n runInInjectionContext,\n} from '@angular/core'\nimport { createBaseQuery } from './create-base-query'\nimport type {\n DefaultError,\n InfiniteData,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\nexport interface InjectInfiniteQueryOptions {\n /**\n * The `Injector` in which to create the infinite query.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): DefinedCreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.\n * Infinite queries can additively \"load more\" data onto an existing set of data or \"infinite scroll\"\n * @param injectInfiniteQueryFn - A function that returns infinite query options.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,\n options?: InjectInfiniteQueryOptions,\n) {\n !options?.injector && assertInInjectionContext(injectInfiniteQuery)\n const injector = options?.injector ?? inject(Injector)\n return runInInjectionContext(injector, () =>\n createBaseQuery(\n injectInfiniteQueryFn,\n InfiniteQueryObserver as typeof QueryObserver,\n ),\n )\n}\n"],"names":[],"mappings":";;;AAgHO,SAAS,oBACd,uBACA,SACA;AACA,IAAC,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,SAAO;AAAA,IAAsB;AAAA,IAAU,MACrC;AAAA,MACE;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"inject-infinite-query.mjs","sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport {\n Injector,\n assertInInjectionContext,\n inject,\n runInInjectionContext,\n} from '@angular/core'\nimport { createBaseQuery } from './create-base-query'\nimport type {\n DefaultError,\n InfiniteData,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\n\nexport interface InjectInfiniteQueryOptions {\n /**\n * The `Injector` in which to create the infinite query.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of\n * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can\n * additively \"load more\" data onto an existing set of data, or \"infinite scroll\".\n *\n * This overload is selected when `initialData` is set on the options returned by `injectInfiniteQueryFn`,\n * so the resulting `data` signal is never `undefined` (unless a `select` changes `TData` to include `undefined`).\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage() && !isFetching()`.\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.fetchInfiniteQuery`.\n * @param injectInfiniteQueryFn - A function returning the {@link DefinedInitialDataInfiniteOptions} to use —\n * everything you can pass to `injectInfiniteQuery`, with `initialData` set. Similar to `computed` from\n * Angular, this function runs in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and\n * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'projects',\n * template: `\n * <!-- `projectsQuery.data()` is never `undefined`, thanks to `initialData` — even if a\n * refetch fails, so the list stays visible alongside the error. -->\n * <ul>\n * @for (page of projectsQuery.data().pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * `,\n * })\n * export class Projects {\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * initialData: { pages: [], pageParams: [] },\n * }))\n * }\n * ```\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): DefinedCreateInfiniteQueryResult<TData, TError>\n\n/**\n * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a\n * unique key. Infinite queries can additively \"load more\" data onto an existing set of data, or\n * \"infinite scroll\".\n *\n * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default\n * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user\n * actions, or add conditions like `hasNextPage() && !isFetching()`. This is the only overload that accepts\n * `queryFn: skipToken`, shown below.\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.fetchInfiniteQuery`.\n * @param injectInfiniteQueryFn - A function returning the {@link UndefinedInitialDataInfiniteOptions} to use\n * — everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs\n * in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,\n * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and\n * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default\n * `InfiniteData<TQueryFnData>` shape.\n *\n * @example\n * Fetching the next page from a button click:\n * ```angular-ts\n * @Component({\n * selector: 'projects-list',\n * template: `\n * <ul>\n * @for (page of projectsQuery.data()?.pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * <button\n * [disabled]=\"!projectsQuery.hasNextPage() || projectsQuery.isFetching()\"\n * (click)=\"projectsQuery.fetchNextPage()\"\n * >\n * Load More\n * </button>\n * `,\n * })\n * export class ProjectsList {\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n * }\n * ```\n *\n * @example\n * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel\n * element after the list:\n * ```angular-ts\n * @Component({\n * selector: 'projects-list',\n * template: `\n * <ul>\n * @for (page of projectsQuery.data()?.pages; track $index) {\n * @for (project of page.projects; track project.id) {\n * <li>{{ project.name }}</li>\n * }\n * }\n * </ul>\n * <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>\n * `,\n * })\n * export class ProjectsList {\n * readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')\n *\n * readonly projectsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n *\n * constructor() {\n * effect((onCleanup) => {\n * const sentinel = this.sentinel()?.nativeElement\n * if (\n * sentinel == null ||\n * !this.projectsQuery.hasNextPage() ||\n * this.projectsQuery.isFetching()\n * ) {\n * return\n * }\n *\n * const observer = new IntersectionObserver(([entry]) => {\n * if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()\n * })\n * observer.observe(sentinel)\n *\n * onCleanup(() => observer.disconnect())\n * })\n * }\n * }\n * ```\n *\n * @example\n * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn` instead of\n * setting `enabled: false`:\n * ```angular-ts\n * @Component({\n * selector: 'comments',\n * template: `\n * @if (postId() == null) {\n * Select a post\n * } @else if (commentsQuery.isPending()) {\n * Loading...\n * } @else if (commentsQuery.isError()) {\n * <span>Error: {{ commentsQuery.error()?.message }}</span>\n * } @else {\n * <ul>\n * @for (page of commentsQuery.data().pages; track $index) {\n * @for (comment of page.comments; track comment.id) {\n * <li>{{ comment.text }}</li>\n * }\n * }\n * </ul>\n * }\n * `,\n * })\n * export class Comments {\n * readonly postId = signal<string | undefined>(undefined)\n *\n * readonly commentsQuery = injectInfiniteQuery(() => ({\n * queryKey: ['post', this.postId(), 'comments'],\n * queryFn:\n * this.postId() != null\n * ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)\n * : skipToken,\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextId,\n * }))\n * }\n * ```\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\n/**\n * This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the\n * `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site —\n * useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided\n * options.\n *\n * @param injectInfiniteQueryFn - A function that returns infinite query options. Similar to `computed` from\n * Angular, this function runs in the reactive context, so signals read inside it drive the query.\n * @param options - Additional configuration.\n * @returns The infinite query result.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n options?: InjectInfiniteQueryOptions,\n): CreateInfiniteQueryResult<TData, TError>\n\nexport function injectInfiniteQuery(\n injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,\n options?: InjectInfiniteQueryOptions,\n) {\n !options?.injector && assertInInjectionContext(injectInfiniteQuery)\n const injector = options?.injector ?? inject(Injector)\n return runInInjectionContext(injector, () =>\n createBaseQuery(\n injectInfiniteQueryFn,\n InfiniteQueryObserver as typeof QueryObserver,\n ),\n )\n}\n"],"names":[],"mappings":";;;AA2RO,SAAS,oBACd,uBACA,SACA;AACA,IAAC,mCAAS,aAAY,yBAAyB,mBAAmB;AAClE,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,SAAO;AAAA,IAAsB;AAAA,IAAU,MACrC;AAAA,MACE;AAAA,MACA;AAAA,IAAA;AAAA,EACF;AAEJ;"}
|
package/inject-is-fetching.d.ts
CHANGED
|
@@ -9,12 +9,44 @@ export interface InjectIsFetchingOptions {
|
|
|
9
9
|
injector?: Injector;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Injects a signal that tracks the number of queries that your application is loading or
|
|
13
|
-
*
|
|
12
|
+
* Injects a signal that tracks the number of queries that your application is loading or fetching in the
|
|
13
|
+
* background (useful for app-wide loading indicators).
|
|
14
14
|
*
|
|
15
|
-
*
|
|
16
|
-
* @param filters - The filters to apply to the query.
|
|
15
|
+
* @param filters - The {@link QueryFilters} to narrow down the matched queries.
|
|
17
16
|
* @param options - Additional configuration
|
|
18
|
-
* @returns
|
|
17
|
+
* @returns A `Signal` with the number of queries that your application is currently loading or fetching in
|
|
18
|
+
* the background.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```angular-ts
|
|
22
|
+
* @Component({
|
|
23
|
+
* selector: 'posts-fetching-indicator',
|
|
24
|
+
* template: `
|
|
25
|
+
* @if (isFetchingPosts()) {
|
|
26
|
+
* <span>Refreshing posts...</span>
|
|
27
|
+
* }
|
|
28
|
+
* `,
|
|
29
|
+
* })
|
|
30
|
+
* export class PostsFetchingIndicator {
|
|
31
|
+
* // How many queries matching the posts prefix are fetching?
|
|
32
|
+
* readonly isFetchingPosts = injectIsFetching({ queryKey: ['posts'] })
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example
|
|
37
|
+
* A global loading indicator for any query fetching in the background, not just the ones on screen:
|
|
38
|
+
* ```angular-ts
|
|
39
|
+
* @Component({
|
|
40
|
+
* selector: 'global-loading-indicator',
|
|
41
|
+
* template: `
|
|
42
|
+
* @if (isFetching()) {
|
|
43
|
+
* <div>Queries are fetching in the background...</div>
|
|
44
|
+
* }
|
|
45
|
+
* `,
|
|
46
|
+
* })
|
|
47
|
+
* export class GlobalLoadingIndicator {
|
|
48
|
+
* readonly isFetching = injectIsFetching()
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
19
51
|
*/
|
|
20
52
|
export declare function injectIsFetching(filters?: QueryFilters, options?: InjectIsFetchingOptions): Signal<number>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inject-is-fetching.mjs","sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { QueryClient, notifyManager } from '@tanstack/query-core'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\nexport interface InjectIsFetchingOptions {\n /**\n * The `Injector` in which to create the isFetching signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or
|
|
1
|
+
{"version":3,"file":"inject-is-fetching.mjs","sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import {\n DestroyRef,\n Injector,\n NgZone,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport { QueryClient, notifyManager } from '@tanstack/query-core'\nimport type { QueryFilters } from '@tanstack/query-core'\nimport type { Signal } from '@angular/core'\n\nexport interface InjectIsFetchingOptions {\n /**\n * The `Injector` in which to create the isFetching signal.\n *\n * If this is not provided, the current injection context will be used instead (via `inject`).\n */\n injector?: Injector\n}\n\n/**\n * Injects a signal that tracks the number of queries that your application is loading or fetching in the\n * background (useful for app-wide loading indicators).\n *\n * @param filters - The {@link QueryFilters} to narrow down the matched queries.\n * @param options - Additional configuration\n * @returns A `Signal` with the number of queries that your application is currently loading or fetching in\n * the background.\n *\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'posts-fetching-indicator',\n * template: `\n * @if (isFetchingPosts()) {\n * <span>Refreshing posts...</span>\n * }\n * `,\n * })\n * export class PostsFetchingIndicator {\n * // How many queries matching the posts prefix are fetching?\n * readonly isFetchingPosts = injectIsFetching({ queryKey: ['posts'] })\n * }\n * ```\n *\n * @example\n * A global loading indicator for any query fetching in the background, not just the ones on screen:\n * ```angular-ts\n * @Component({\n * selector: 'global-loading-indicator',\n * template: `\n * @if (isFetching()) {\n * <div>Queries are fetching in the background...</div>\n * }\n * `,\n * })\n * export class GlobalLoadingIndicator {\n * readonly isFetching = injectIsFetching()\n * }\n * ```\n */\nexport function injectIsFetching(\n filters?: QueryFilters,\n options?: InjectIsFetchingOptions,\n): Signal<number> {\n !options?.injector && assertInInjectionContext(injectIsFetching)\n const injector = options?.injector ?? inject(Injector)\n const destroyRef = injector.get(DestroyRef)\n const ngZone = injector.get(NgZone)\n const queryClient = injector.get(QueryClient)\n\n const cache = queryClient.getQueryCache()\n // isFetching is the prev value initialized on mount *\n let isFetching = queryClient.isFetching(filters)\n\n const result = signal(isFetching)\n\n const unsubscribe = ngZone.runOutsideAngular(() =>\n cache.subscribe(\n notifyManager.batchCalls(() => {\n const newIsFetching = queryClient.isFetching(filters)\n if (isFetching !== newIsFetching) {\n // * and update with each change\n isFetching = newIsFetching\n ngZone.run(() => {\n result.set(isFetching)\n })\n }\n }),\n ),\n )\n\n destroyRef.onDestroy(unsubscribe)\n\n return result\n}\n"],"names":[],"mappings":";;AA8DO,SAAS,iBACd,SACA,SACgB;AAChB,IAAC,mCAAS,aAAY,yBAAyB,gBAAgB;AAC/D,QAAM,YAAW,mCAAS,aAAY,OAAO,QAAQ;AACrD,QAAM,aAAa,SAAS,IAAI,UAAU;AAC1C,QAAM,SAAS,SAAS,IAAI,MAAM;AAClC,QAAM,cAAc,SAAS,IAAI,WAAW;AAE5C,QAAM,QAAQ,YAAY,cAAA;AAE1B,MAAI,aAAa,YAAY,WAAW,OAAO;AAE/C,QAAM,SAAS,OAAO,UAAU;AAEhC,QAAM,cAAc,OAAO;AAAA,IAAkB,MAC3C,MAAM;AAAA,MACJ,cAAc,WAAW,MAAM;AAC7B,cAAM,gBAAgB,YAAY,WAAW,OAAO;AACpD,YAAI,eAAe,eAAe;AAEhC,uBAAa;AACb,iBAAO,IAAI,MAAM;AACf,mBAAO,IAAI,UAAU;AAAA,UACvB,CAAC;AAAA,QACH;AAAA,MACF,CAAC;AAAA,IAAA;AAAA,EACH;AAGF,aAAW,UAAU,WAAW;AAEhC,SAAO;AACT;"}
|
package/inject-is-mutating.d.ts
CHANGED
|
@@ -9,11 +9,27 @@ export interface InjectIsMutatingOptions {
|
|
|
9
9
|
injector?: Injector;
|
|
10
10
|
}
|
|
11
11
|
/**
|
|
12
|
-
* Injects a signal that tracks the number of mutations that your application
|
|
12
|
+
* Injects a signal that tracks the number of mutations that your application currently has `pending`
|
|
13
|
+
* (useful for app-wide loading indicators).
|
|
13
14
|
*
|
|
14
|
-
*
|
|
15
|
-
* @param filters - The filters to apply to the query.
|
|
15
|
+
* @param filters - The {@link MutationFilters} to narrow down the matched mutations.
|
|
16
16
|
* @param options - Additional configuration
|
|
17
|
-
* @returns A
|
|
17
|
+
* @returns A `Signal` with the number of mutations that your application currently has `pending`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```angular-ts
|
|
21
|
+
* @Component({
|
|
22
|
+
* selector: 'posts-mutating-indicator',
|
|
23
|
+
* template: `
|
|
24
|
+
* @if (isMutatingPosts()) {
|
|
25
|
+
* <span>Saving posts...</span>
|
|
26
|
+
* }
|
|
27
|
+
* `,
|
|
28
|
+
* })
|
|
29
|
+
* export class PostsMutatingIndicator {
|
|
30
|
+
* // How many mutations matching the posts prefix are in progress?
|
|
31
|
+
* readonly isMutatingPosts = injectIsMutating({ mutationKey: ['posts'] })
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
18
34
|
*/
|
|
19
35
|
export declare function injectIsMutating(filters?: MutationFilters, options?: InjectIsMutatingOptions): Signal<number>;
|