@tanstack/angular-query 5.0.0 → 5.108.0

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.
@@ -2,50 +2,186 @@ import { DefaultError, InfiniteData, QueryKey } from '@tanstack/query-core';
2
2
  import { DefinedInitialDataInfiniteOptions, UndefinedInitialDataInfiniteOptions } from './infinite-query-options.js';
3
3
  import { CreateInfiniteQueryOptions, CreateInfiniteQueryResult, DefinedCreateInfiniteQueryResult } from './types.js';
4
4
  /**
5
- * This overload is selected when `initialData` is set, so the resulting `data` signal is never `undefined`
6
- * (unless a `select` changes `TData` to include `undefined`).
7
- * @param optionsFn - A function returning infinite-query options with `initialData` set. Similar to
8
- * `computed` from Angular, this function runs in the reactive context.
9
- * @returns The infinite query result, typed so that `data` is never `undefined`.
5
+ * The options for `injectInfiniteQuery` are identical to `injectQuery`, with the addition of
6
+ * `initialPageParam`, `getNextPageParam`, `getPreviousPageParam`, and `maxPages`. Infinite queries can
7
+ * additively "load more" data onto an existing set of data, or "infinite scroll".
8
+ *
9
+ * This overload is selected when `initialData` is known to be defined on the options returned by
10
+ * `optionsFn`, so the resulting `data` signal is never `undefined` (unless a `select` changes
11
+ * `TData` to include `undefined`).
12
+ * @param optionsFn - A function returning the {@link DefinedInitialDataInfiniteOptions} to use —
13
+ * everything you can pass to `injectInfiniteQuery`, with `initialData` known to be defined. Similar to
14
+ * `computed` from Angular, this function runs in the reactive context, so signals read inside it drive the
15
+ * query.
16
+ * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
17
+ * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
18
+ * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
19
+ * `InfiniteData<TQueryFnData>` shape.
20
+ * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
21
+ * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
22
+ * actions, or add conditions like `hasNextPage() && !isFetching()`.
10
23
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
11
- * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
12
- * `queryClient.infiniteQuery`.
24
+ * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs
25
+ * like `queryClient.infiniteQuery`.
26
+ * @example
27
+ * ```angular-ts
28
+ * @Component({
29
+ * selector: 'projects',
30
+ * template: `
31
+ * <!-- projectsQuery.data() is never undefined, thanks to initialData — even if a
32
+ * refetch fails, so the list stays visible alongside the error. -->
33
+ * <ul>
34
+ * @for (page of projectsQuery.data().pages; track $index) {
35
+ * @for (project of page.projects; track project.id) {
36
+ * <li>{{ project.name }}</li>
37
+ * }
38
+ * }
39
+ * </ul>
40
+ * `,
41
+ * })
42
+ * export class Projects {
43
+ * readonly projectsQuery = injectInfiniteQuery(() => ({
44
+ * queryKey: ['projects'],
45
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
46
+ * initialPageParam: 0,
47
+ * getNextPageParam: (lastPage) => lastPage.nextId,
48
+ * initialData: { pages: [], pageParams: [] },
49
+ * }))
50
+ * }
51
+ * ```
13
52
  */
14
53
  export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: () => DefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): DefinedCreateInfiniteQueryResult<TData, TError>;
15
54
  /**
16
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
17
- * Infinite queries can additively "load more" data onto an existing set of data or support infinite scroll.
18
- * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,
19
- * this function runs in the reactive context, so signals read inside it drive the query.
20
- * @returns The infinite query result.
55
+ * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a
56
+ * unique key. Infinite queries can additively "load more" data onto an existing set of data, or
57
+ * "infinite scroll".
58
+ * @param optionsFn - A function returning the {@link UndefinedInitialDataInfiniteOptions} to use
59
+ * — everything you can pass to `injectInfiniteQuery`. Similar to `computed` from Angular, this function runs
60
+ * in the reactive context, so signals read inside it drive the query.
61
+ * @returns The same signals as `injectQuery`, with the addition of `fetchNextPage`, `fetchPreviousPage`,
62
+ * `hasNextPage`, `hasPreviousPage`, `isFetchingNextPage`, and `isFetchingPreviousPage`. `data().pages` and
63
+ * `data().pageParams` are also added, as long as a `select` doesn't change `TData` away from its default
64
+ * `InfiniteData<TQueryFnData>` shape.
65
+ * @remarks Keep in mind that imperative fetch calls, such as `fetchNextPage`, may interfere with the default
66
+ * refetch behavior, resulting in outdated data. Make sure to call these functions only in response to user
67
+ * actions, or add conditions like `hasNextPage() && !isFetching()`. `queryFn: skipToken` is also accepted,
68
+ * shown below.
21
69
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
22
- * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and
23
- * `queryClient.infiniteQuery`.
70
+ * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs
71
+ * like `queryClient.infiniteQuery`.
24
72
  * @example
73
+ * Fetching the next page from a button click:
25
74
  * ```angular-ts
26
75
  * @Component({
27
- * selector: 'projects',
76
+ * selector: 'projects-list',
28
77
  * template: `
29
- * @if (query.isPending()) {
30
- * Loading...
31
- * } @else if (query.isError()) {
32
- * <span>Error: {{ query.error()?.message }}</span>
33
- * } @else {
34
- * @for (page of query.data().pages; track $index) {
35
- * @for (project of page; track project.id) {
36
- * <p>{{ project.name }}</p>
78
+ * <ul>
79
+ * @for (page of projectsQuery.data()?.pages; track $index) {
80
+ * @for (project of page.projects; track project.id) {
81
+ * <li>{{ project.name }}</li>
37
82
  * }
38
83
  * }
39
- * <button (click)="query.fetchNextPage()">Load more</button>
40
- * }
84
+ * </ul>
85
+ * <button
86
+ * [disabled]="!projectsQuery.hasNextPage() || projectsQuery.isFetching()"
87
+ * (click)="projectsQuery.fetchNextPage()"
88
+ * >
89
+ * Load More
90
+ * </button>
41
91
  * `,
42
92
  * })
43
- * export class Projects {
44
- * readonly query = injectInfiniteQuery(() => ({
93
+ * export class ProjectsList {
94
+ * readonly projectsQuery = injectInfiniteQuery(() => ({
45
95
  * queryKey: ['projects'],
46
96
  * queryFn: ({ pageParam }) => fetchProjects(pageParam),
47
97
  * initialPageParam: 0,
48
- * getNextPageParam: (lastPage) => lastPage.nextCursor,
98
+ * getNextPageParam: (lastPage) => lastPage.nextId,
99
+ * }))
100
+ * }
101
+ * ```
102
+ * @example
103
+ * Fetching the next page automatically as the user scrolls, using an `IntersectionObserver` on a sentinel
104
+ * element after the list:
105
+ * ```angular-ts
106
+ * @Component({
107
+ * selector: 'projects-list',
108
+ * template: `
109
+ * <ul>
110
+ * @for (page of projectsQuery.data()?.pages; track $index) {
111
+ * @for (project of page.projects; track project.id) {
112
+ * <li>{{ project.name }}</li>
113
+ * }
114
+ * }
115
+ * </ul>
116
+ * <div #sentinel>{{ projectsQuery.isFetchingNextPage() ? 'Loading more...' : '' }}</div>
117
+ * `,
118
+ * })
119
+ * export class ProjectsList {
120
+ * readonly sentinel = viewChild<ElementRef<HTMLElement>>('sentinel')
121
+ *
122
+ * readonly projectsQuery = injectInfiniteQuery(() => ({
123
+ * queryKey: ['projects'],
124
+ * queryFn: ({ pageParam }) => fetchProjects(pageParam),
125
+ * initialPageParam: 0,
126
+ * getNextPageParam: (lastPage) => lastPage.nextId,
127
+ * }))
128
+ *
129
+ * constructor() {
130
+ * effect((onCleanup) => {
131
+ * const sentinel = this.sentinel()?.nativeElement
132
+ * if (
133
+ * sentinel == null ||
134
+ * !this.projectsQuery.hasNextPage() ||
135
+ * this.projectsQuery.isFetching()
136
+ * ) {
137
+ * return
138
+ * }
139
+ *
140
+ * const observer = new IntersectionObserver(([entry]) => {
141
+ * if (entry?.isIntersecting) this.projectsQuery.fetchNextPage()
142
+ * })
143
+ * observer.observe(sentinel)
144
+ *
145
+ * onCleanup(() => observer.disconnect())
146
+ * })
147
+ * }
148
+ * }
149
+ * ```
150
+ * @example
151
+ * A query that's disabled, type safe, until `postId` is set — pass `skipToken` as `queryFn` instead of
152
+ * setting `enabled: false`:
153
+ * ```angular-ts
154
+ * @Component({
155
+ * selector: 'comments',
156
+ * template: `
157
+ * @if (postId() == null) {
158
+ * Select a post
159
+ * } @else if (commentsQuery.isPending()) {
160
+ * Loading...
161
+ * } @else if (commentsQuery.isError()) {
162
+ * <span>Error: {{ commentsQuery.error()?.message }}</span>
163
+ * } @else {
164
+ * <ul>
165
+ * @for (page of commentsQuery.data().pages; track $index) {
166
+ * @for (comment of page.comments; track comment.id) {
167
+ * <li>{{ comment.text }}</li>
168
+ * }
169
+ * }
170
+ * </ul>
171
+ * }
172
+ * `,
173
+ * })
174
+ * export class Comments {
175
+ * readonly postId = signal<string | undefined>(undefined)
176
+ *
177
+ * readonly commentsQuery = injectInfiniteQuery(() => ({
178
+ * queryKey: ['post', this.postId(), 'comments'],
179
+ * queryFn:
180
+ * this.postId() != null
181
+ * ? ({ pageParam }) => fetchComments(this.postId()!, pageParam)
182
+ * : skipToken,
183
+ * initialPageParam: 0,
184
+ * getNextPageParam: (lastPage) => lastPage.nextId,
49
185
  * }))
50
186
  * }
51
187
  * ```
@@ -53,10 +189,11 @@ export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError,
53
189
  export declare function injectInfiniteQuery<TQueryFnData, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(optionsFn: () => UndefinedInitialDataInfiniteOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): CreateInfiniteQueryResult<TData, TError>;
54
190
  /**
55
191
  * This overload accepts the general {@link CreateInfiniteQueryOptions} shape rather than the
56
- * `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call
57
- * site — useful when wrapping `injectInfiniteQuery` in your own helper.
58
- * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,
59
- * this function runs in the reactive context, so signals read inside it drive the query.
192
+ * `initialData`-aware overloads above, so whether `data` is defined can't be inferred from the call site —
193
+ * useful when wrapping `injectInfiniteQuery` in your own helper function that forwards caller-provided
194
+ * options.
195
+ * @param optionsFn - A function that returns infinite query options. Similar to `computed` from
196
+ * Angular, this function runs in the reactive context, so signals read inside it drive the query.
60
197
  * @returns The infinite query result.
61
198
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries
62
199
  */
@@ -1 +1 @@
1
- {"version":3,"file":"inject-infinite-query.mjs","names":[],"sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { assertInInjectionContext, untracked } from '@angular/core'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { injectBaseQuery } from './inject-base-query'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { infiniteQueryResultFields } from './utils/result-fields'\nimport { signalProxy } from './utils/signal-proxy'\nimport type { Signal } from '@angular/core'\nimport type {\n DefaultError,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n RefetchOptions,\n} from '@tanstack/query-core'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\n\n/**\n * This overload is selected when `initialData` is set, so the resulting `data` signal is never `undefined`\n * (unless a `select` changes `TData` to include `undefined`).\n * @param optionsFn - A function returning infinite-query options with `initialData` set. Similar to\n * `computed` from Angular, this function runs in the reactive context.\n * @returns The infinite query result, typed so that `data` is never `undefined`.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and\n * `queryClient.infiniteQuery`.\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\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 support infinite scroll.\n * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,\n * this function runs in the reactive context, so signals read inside it drive the query.\n * @returns The infinite query result.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and\n * `queryClient.infiniteQuery`.\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'projects',\n * template: `\n * @if (query.isPending()) {\n * Loading...\n * } @else if (query.isError()) {\n * <span>Error: {{ query.error()?.message }}</span>\n * } @else {\n * @for (page of query.data().pages; track $index) {\n * @for (project of page; track project.id) {\n * <p>{{ project.name }}</p>\n * }\n * }\n * <button (click)=\"query.fetchNextPage()\">Load more</button>\n * }\n * `,\n * })\n * export class Projects {\n * readonly query = injectInfiniteQuery(() => ({\n * queryKey: ['projects'],\n * queryFn: ({ pageParam }) => fetchProjects(pageParam),\n * initialPageParam: 0,\n * getNextPageParam: (lastPage) => lastPage.nextCursor,\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 optionsFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\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\n * site — useful when wrapping `injectInfiniteQuery` in your own helper.\n * @param optionsFn - A function that returns infinite query options. Similar to `computed` from Angular,\n * this function runs in the reactive context, so signals read inside it drive the query.\n * @returns The infinite query result.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): CreateInfiniteQueryResult<TData, TError>\n\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () =>\n | DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n | CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n):\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectInfiniteQuery)\n }\n const outsideZone = injectQueryZone()\n const [resultSignal, getObserver] = injectBaseQuery(\n optionsFn,\n InfiniteQueryObserver as typeof QueryObserver,\n )\n const getInfiniteObserver = () =>\n getObserver() as InfiniteQueryObserver<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n return Object.assign(\n signalProxy(\n resultSignal as Signal<InfiniteQueryObserverResult<TData, TError>>,\n infiniteQueryResultFields,\n ),\n {\n refetch: (options?: RefetchOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().refetch(options)),\n ),\n fetchNextPage: (options?: FetchNextPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchNextPage(options)),\n ),\n fetchPreviousPage: (options?: FetchPreviousPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchPreviousPage(options)),\n ),\n },\n ) as unknown as\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;AAoIA,SAAgB,oBAOd,WAiB2C;CAC3C,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,mBAAmB;CAE9C,MAAM,cAAc,gBAAgB;CACpC,MAAM,CAAC,cAAc,eAAe,gBAClC,WACA,qBACF;CACA,MAAM,4BACJ,YAAY;CAOd,OAAO,OAAO,OACZ,YACE,cACA,yBACF,GACA;EACE,UAAU,YACR,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,QAAQ,OAAO,CAAC,CACxD;EACF,gBAAgB,YACd,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,cAAc,OAAO,CAAC,CAC9D;EACF,oBAAoB,YAClB,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,kBAAkB,OAAO,CAAC,CAClE;CACJ,CACF;AAGF"}
1
+ {"version":3,"file":"inject-infinite-query.mjs","names":[],"sources":["../src/inject-infinite-query.ts"],"sourcesContent":["import { assertInInjectionContext, untracked } from '@angular/core'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { injectBaseQuery } from './inject-base-query'\nimport { injectQueryZone } from './utils/inject-query-zone'\nimport { infiniteQueryResultFields } from './utils/result-fields'\nimport { signalProxy } from './utils/signal-proxy'\nimport type { Signal } from '@angular/core'\nimport type {\n DefaultError,\n FetchNextPageOptions,\n FetchPreviousPageOptions,\n InfiniteData,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n RefetchOptions,\n} from '@tanstack/query-core'\nimport type {\n DefinedInitialDataInfiniteOptions,\n UndefinedInitialDataInfiniteOptions,\n} from './infinite-query-options'\nimport type {\n CreateInfiniteQueryOptions,\n CreateInfiniteQueryResult,\n DefinedCreateInfiniteQueryResult,\n} from './types'\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 known to be defined on the options returned by\n * `optionsFn`, so the resulting `data` signal is never `undefined` (unless a `select` changes\n * `TData` to include `undefined`).\n * @param optionsFn - A function returning the {@link DefinedInitialDataInfiniteOptions} to use —\n * everything you can pass to `injectInfiniteQuery`, with `initialData` known to be defined. Similar to\n * `computed` from Angular, this function runs in the reactive context, so signals read inside it drive the\n * query.\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 * @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 https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.infiniteQuery`.\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 optionsFn: () => DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\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 * @param optionsFn - 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 * @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 * @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()`. `queryFn: skipToken` is also accepted,\n * shown below.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n * @see {@link infiniteQueryOptions} to share these options between `injectInfiniteQuery` and imperative APIs\n * like `queryClient.infiniteQuery`.\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 * @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 * @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 optionsFn: () => UndefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\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 * @param optionsFn - 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 * @returns The infinite query result.\n * @see https://tanstack.com/query/latest/docs/framework/angular/guides/infinite-queries\n */\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () => CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n): CreateInfiniteQueryResult<TData, TError>\n\nexport function injectInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n optionsFn: () =>\n | DefinedInitialDataInfiniteOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n | CreateInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >,\n):\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectInfiniteQuery)\n }\n const outsideZone = injectQueryZone()\n const [resultSignal, getObserver] = injectBaseQuery(\n optionsFn,\n InfiniteQueryObserver as typeof QueryObserver,\n )\n const getInfiniteObserver = () =>\n getObserver() as InfiniteQueryObserver<\n TQueryFnData,\n TError,\n TData,\n TQueryKey,\n TPageParam\n >\n return Object.assign(\n signalProxy(\n resultSignal as Signal<InfiniteQueryObserverResult<TData, TError>>,\n infiniteQueryResultFields,\n ),\n {\n refetch: (options?: RefetchOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().refetch(options)),\n ),\n fetchNextPage: (options?: FetchNextPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchNextPage(options)),\n ),\n fetchPreviousPage: (options?: FetchPreviousPageOptions) =>\n outsideZone(() =>\n untracked(() => getInfiniteObserver().fetchPreviousPage(options)),\n ),\n },\n ) as unknown as\n | DefinedCreateInfiniteQueryResult<TData, TError>\n | CreateInfiniteQueryResult<TData, TError>\n}\n"],"mappings":";;;;;;;AA6QA,SAAgB,oBAOd,WAiB2C;CAC3C,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,mBAAmB;CAE9C,MAAM,cAAc,gBAAgB;CACpC,MAAM,CAAC,cAAc,eAAe,gBAClC,WACA,qBACF;CACA,MAAM,4BACJ,YAAY;CAOd,OAAO,OAAO,OACZ,YACE,cACA,yBACF,GACA;EACE,UAAU,YACR,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,QAAQ,OAAO,CAAC,CACxD;EACF,gBAAgB,YACd,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,cAAc,OAAO,CAAC,CAC9D;EACF,oBAAoB,YAClB,kBACE,gBAAgB,oBAAoB,CAAC,CAAC,kBAAkB,OAAO,CAAC,CAClE;CACJ,CACF;AAGF"}
@@ -3,9 +3,40 @@ import { QueryFilters } from '@tanstack/query-core';
3
3
  /**
4
4
  * Injects a signal that tracks the number of queries that your application is loading or fetching in the
5
5
  * background (useful for app-wide loading indicators).
6
- *
7
- * Can be used for app-wide loading indicators.
8
- * @param filters - A reactive factory for the filters.
9
- * @returns signal with number of loading or fetching queries.
6
+ * @param filters - A function returning the {@link QueryFilters} to narrow down the matched queries. Similar
7
+ * to `computed` from Angular, this function runs in the reactive context, so signals read inside it
8
+ * re-narrow the matched queries.
9
+ * @returns A `Signal` with the number of queries that your application is currently loading or fetching in
10
+ * the background.
11
+ * @example
12
+ * ```angular-ts
13
+ * @Component({
14
+ * selector: 'posts-fetching-indicator',
15
+ * template: `
16
+ * @if (isFetchingPosts()) {
17
+ * <span>Refreshing posts...</span>
18
+ * }
19
+ * `,
20
+ * })
21
+ * export class PostsFetchingIndicator {
22
+ * // How many queries matching the posts prefix are fetching?
23
+ * readonly isFetchingPosts = injectIsFetching(() => ({ queryKey: ['posts'] }))
24
+ * }
25
+ * ```
26
+ * @example
27
+ * A global loading indicator for any query fetching in the background, not just the ones on screen:
28
+ * ```angular-ts
29
+ * @Component({
30
+ * selector: 'global-loading-indicator',
31
+ * template: `
32
+ * @if (isFetching()) {
33
+ * <div>Queries are fetching in the background...</div>
34
+ * }
35
+ * `,
36
+ * })
37
+ * export class GlobalLoadingIndicator {
38
+ * readonly isFetching = injectIsFetching()
39
+ * }
40
+ * ```
10
41
  */
11
42
  export declare function injectIsFetching(filters?: () => Omit<QueryFilters, 'fetchStatus'>): Signal<number>;
@@ -5,10 +5,41 @@ import { assertInInjectionContext, inject } from "@angular/core";
5
5
  /**
6
6
  * Injects a signal that tracks the number of queries that your application is loading or fetching in the
7
7
  * background (useful for app-wide loading indicators).
8
- *
9
- * Can be used for app-wide loading indicators.
10
- * @param filters - A reactive factory for the filters.
11
- * @returns signal with number of loading or fetching queries.
8
+ * @param filters - A function returning the {@link QueryFilters} to narrow down the matched queries. Similar
9
+ * to `computed` from Angular, this function runs in the reactive context, so signals read inside it
10
+ * re-narrow the matched queries.
11
+ * @returns A `Signal` with the number of queries that your application is currently loading or fetching in
12
+ * the background.
13
+ * @example
14
+ * ```angular-ts
15
+ * @Component({
16
+ * selector: 'posts-fetching-indicator',
17
+ * template: `
18
+ * @if (isFetchingPosts()) {
19
+ * <span>Refreshing posts...</span>
20
+ * }
21
+ * `,
22
+ * })
23
+ * export class PostsFetchingIndicator {
24
+ * // How many queries matching the posts prefix are fetching?
25
+ * readonly isFetchingPosts = injectIsFetching(() => ({ queryKey: ['posts'] }))
26
+ * }
27
+ * ```
28
+ * @example
29
+ * A global loading indicator for any query fetching in the background, not just the ones on screen:
30
+ * ```angular-ts
31
+ * @Component({
32
+ * selector: 'global-loading-indicator',
33
+ * template: `
34
+ * @if (isFetching()) {
35
+ * <div>Queries are fetching in the background...</div>
36
+ * }
37
+ * `,
38
+ * })
39
+ * export class GlobalLoadingIndicator {
40
+ * readonly isFetching = injectIsFetching()
41
+ * }
42
+ * ```
12
43
  */
13
44
  function injectIsFetching(filters = () => ({})) {
14
45
  if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsFetching);
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-fetching.mjs","names":[],"sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type { QueryFilters } from '@tanstack/query-core'\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 * Can be used for app-wide loading indicators.\n * @param filters - A reactive factory for the filters.\n * @returns signal with number of loading or fetching queries.\n */\nexport function injectIsFetching(\n filters: () => Omit<QueryFilters, 'fetchStatus'> = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsFetching)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getQueryCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isFetching(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,iBACd,iBAA0D,CAAC,IAC3C;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,cAAc;CAExC,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
1
+ {"version":3,"file":"inject-is-fetching.mjs","names":[],"sources":["../src/inject-is-fetching.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type { QueryFilters } from '@tanstack/query-core'\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 * @param filters - A function returning the {@link QueryFilters} to narrow down the matched queries. Similar\n * to `computed` from Angular, this function runs in the reactive context, so signals read inside it\n * re-narrow the matched queries.\n * @returns A `Signal` with the number of queries that your application is currently loading or fetching in\n * the background.\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 * @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: () => Omit<QueryFilters, 'fetchStatus'> = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsFetching)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getQueryCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isFetching(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,SAAgB,iBACd,iBAA0D,CAAC,IAC3C;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,cAAc;CAExC,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
@@ -3,9 +3,24 @@ import { MutationFilters } from '@tanstack/query-core';
3
3
  /**
4
4
  * Injects a signal that tracks the number of mutations that your application currently has `pending`
5
5
  * (useful for app-wide loading indicators).
6
- *
7
- * Can be used for app-wide loading indicators.
8
- * @param filters - A reactive factory for the filters.
9
- * @returns A read-only signal with the number of fetching mutations.
6
+ * @param filters - A function returning the {@link MutationFilters} to narrow down the matched mutations.
7
+ * Similar to `computed` from Angular, this function runs in the reactive context, so signals read inside it
8
+ * re-narrow the matched mutations.
9
+ * @returns A `Signal` with the number of mutations that your application currently has `pending`.
10
+ * @example
11
+ * ```angular-ts
12
+ * @Component({
13
+ * selector: 'posts-mutating-indicator',
14
+ * template: `
15
+ * @if (isMutatingPosts()) {
16
+ * <span>Saving posts...</span>
17
+ * }
18
+ * `,
19
+ * })
20
+ * export class PostsMutatingIndicator {
21
+ * // How many mutations matching the posts prefix are in progress?
22
+ * readonly isMutatingPosts = injectIsMutating(() => ({ mutationKey: ['posts'] }))
23
+ * }
24
+ * ```
10
25
  */
11
26
  export declare function injectIsMutating(filters?: () => Omit<MutationFilters, 'status'>): Signal<number>;
@@ -5,10 +5,25 @@ import { assertInInjectionContext, inject } from "@angular/core";
5
5
  /**
6
6
  * Injects a signal that tracks the number of mutations that your application currently has `pending`
7
7
  * (useful for app-wide loading indicators).
8
- *
9
- * Can be used for app-wide loading indicators.
10
- * @param filters - A reactive factory for the filters.
11
- * @returns A read-only signal with the number of fetching mutations.
8
+ * @param filters - A function returning the {@link MutationFilters} to narrow down the matched mutations.
9
+ * Similar to `computed` from Angular, this function runs in the reactive context, so signals read inside it
10
+ * re-narrow the matched mutations.
11
+ * @returns A `Signal` with the number of mutations that your application currently has `pending`.
12
+ * @example
13
+ * ```angular-ts
14
+ * @Component({
15
+ * selector: 'posts-mutating-indicator',
16
+ * template: `
17
+ * @if (isMutatingPosts()) {
18
+ * <span>Saving posts...</span>
19
+ * }
20
+ * `,
21
+ * })
22
+ * export class PostsMutatingIndicator {
23
+ * // How many mutations matching the posts prefix are in progress?
24
+ * readonly isMutatingPosts = injectIsMutating(() => ({ mutationKey: ['posts'] }))
25
+ * }
26
+ * ```
12
27
  */
13
28
  function injectIsMutating(filters = () => ({})) {
14
29
  if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsMutating);
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-mutating.mjs","names":[],"sources":["../src/inject-is-mutating.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type { MutationFilters } from '@tanstack/query-core'\n\n/**\n * Injects a signal that tracks the number of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n *\n * Can be used for app-wide loading indicators.\n * @param filters - A reactive factory for the filters.\n * @returns A read-only signal with the number of fetching mutations.\n */\nexport function injectIsMutating(\n filters: () => Omit<MutationFilters, 'status'> = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsMutating)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getMutationCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isMutating(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;AAcA,SAAgB,iBACd,iBAAwD,CAAC,IACzC;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,iBAAiB;CAE3C,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
1
+ {"version":3,"file":"inject-is-mutating.mjs","names":[],"sources":["../src/inject-is-mutating.ts"],"sourcesContent":["import { assertInInjectionContext, inject } from '@angular/core'\nimport { QueryClient } from '@tanstack/query-core'\nimport { injectExternalStore } from './utils/inject-external-store'\nimport type { Signal } from '@angular/core'\nimport type { MutationFilters } from '@tanstack/query-core'\n\n/**\n * Injects a signal that tracks the number of mutations that your application currently has `pending`\n * (useful for app-wide loading indicators).\n * @param filters - A function returning the {@link MutationFilters} to narrow down the matched mutations.\n * Similar to `computed` from Angular, this function runs in the reactive context, so signals read inside it\n * re-narrow the matched mutations.\n * @returns A `Signal` with the number of mutations that your application currently has `pending`.\n * @example\n * ```angular-ts\n * @Component({\n * selector: 'posts-mutating-indicator',\n * template: `\n * @if (isMutatingPosts()) {\n * <span>Saving posts...</span>\n * }\n * `,\n * })\n * export class PostsMutatingIndicator {\n * // How many mutations matching the posts prefix are in progress?\n * readonly isMutatingPosts = injectIsMutating(() => ({ mutationKey: ['posts'] }))\n * }\n * ```\n */\nexport function injectIsMutating(\n filters: () => Omit<MutationFilters, 'status'> = () => ({}),\n): Signal<number> {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsMutating)\n }\n const queryClient = inject(QueryClient)\n const cache = queryClient.getMutationCache()\n\n return injectExternalStore(() => ({\n getSnapshot: () => queryClient.isMutating(filters()),\n subscribe: (onStoreChange) => cache.subscribe(onStoreChange),\n }))\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BA,SAAgB,iBACd,iBAAwD,CAAC,IACzC;CAChB,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,gBAAgB;CAE3C,MAAM,cAAc,OAAO,WAAW;CACtC,MAAM,QAAQ,YAAY,iBAAiB;CAE3C,OAAO,2BAA2B;EAChC,mBAAmB,YAAY,WAAW,QAAQ,CAAC;EACnD,YAAY,kBAAkB,MAAM,UAAU,aAAa;CAC7D,EAAE;AACJ"}
@@ -1,8 +1,10 @@
1
1
  import { Provider, Signal } from '@angular/core';
2
2
  /**
3
- * Injects a readonly signal that is true while the persistence integration restores
4
- * cached query data. Returns false when no restoration is in progress.
5
- * @returns The current restoration state.
3
+ * Injects a signal that tracks whether a restore (e.g. from a persisted client, wired up via
4
+ * `withPersistQueryClient`) is currently in progress. `injectQuery` and friends also check this internally
5
+ * to avoid race conditions between the restore and initializing queries.
6
+ * @returns A readonly `Signal<boolean>` — `true` while a restore is in progress, `false` otherwise (the
7
+ * default when no persistence integration is registered).
6
8
  */
7
9
  export declare function injectIsRestoring(): Signal<boolean>;
8
10
  /**
@@ -5,9 +5,11 @@ import { InjectionToken, assertInInjectionContext, inject, signal } from "@angul
5
5
  */
6
6
  var IS_RESTORING = new InjectionToken("", { factory: () => signal(false).asReadonly() });
7
7
  /**
8
- * Injects a readonly signal that is true while the persistence integration restores
9
- * cached query data. Returns false when no restoration is in progress.
10
- * @returns The current restoration state.
8
+ * Injects a signal that tracks whether a restore (e.g. from a persisted client, wired up via
9
+ * `withPersistQueryClient`) is currently in progress. `injectQuery` and friends also check this internally
10
+ * to avoid race conditions between the restore and initializing queries.
11
+ * @returns A readonly `Signal<boolean>` — `true` while a restore is in progress, `false` otherwise (the
12
+ * default when no persistence integration is registered).
11
13
  */
12
14
  function injectIsRestoring() {
13
15
  if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectIsRestoring);
@@ -1 +1 @@
1
- {"version":3,"file":"inject-is-restoring.mjs","names":[],"sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n InjectionToken,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\n/**\n * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`\n */\nconst IS_RESTORING = new InjectionToken('', {\n factory: () => signal(false).asReadonly(),\n})\n\n/**\n * Injects a readonly signal that is true while the persistence integration restores\n * cached query data. Returns false when no restoration is in progress.\n * @returns The current restoration state.\n */\nexport function injectIsRestoring() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsRestoring)\n }\n return inject(IS_RESTORING)\n}\n\n/**\n * Supplies injector-scoped restoration state to the Angular Query integrations.\n * The factory runs once in Angular's injection context.\n * @internal\n * @param isRestoringFactory - Produces the restoration signal for this injector.\n * @returns The provider that makes the restoration state injectable.\n */\nexport function provideIsRestoring(\n isRestoringFactory: () => Signal<boolean>,\n): Provider {\n return {\n provide: IS_RESTORING,\n useFactory: isRestoringFactory,\n }\n}\n"],"mappings":";;;;;AAWA,IAAM,eAAe,IAAI,eAAe,IAAI,EAC1C,eAAe,OAAO,KAAK,CAAC,CAAC,WAAW,EAC1C,CAAC;;;;;;AAOD,SAAgB,oBAAoB;CAClC,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,iBAAiB;CAE5C,OAAO,OAAO,YAAY;AAC5B;;;;;;;;AASA,SAAgB,mBACd,oBACU;CACV,OAAO;EACL,SAAS;EACT,YAAY;CACd;AACF"}
1
+ {"version":3,"file":"inject-is-restoring.mjs","names":[],"sources":["../src/inject-is-restoring.ts"],"sourcesContent":["import {\n InjectionToken,\n assertInInjectionContext,\n inject,\n signal,\n} from '@angular/core'\nimport type { Provider, Signal } from '@angular/core'\n\n/**\n * Internal token used to track isRestoring state, accessible in public API through `injectIsRestoring` and set via `provideIsRestoring`\n */\nconst IS_RESTORING = new InjectionToken('', {\n factory: () => signal(false).asReadonly(),\n})\n\n/**\n * Injects a signal that tracks whether a restore (e.g. from a persisted client, wired up via\n * `withPersistQueryClient`) is currently in progress. `injectQuery` and friends also check this internally\n * to avoid race conditions between the restore and initializing queries.\n * @returns A readonly `Signal<boolean>` — `true` while a restore is in progress, `false` otherwise (the\n * default when no persistence integration is registered).\n */\nexport function injectIsRestoring() {\n if (typeof ngDevMode === 'undefined' || ngDevMode) {\n assertInInjectionContext(injectIsRestoring)\n }\n return inject(IS_RESTORING)\n}\n\n/**\n * Supplies injector-scoped restoration state to the Angular Query integrations.\n * The factory runs once in Angular's injection context.\n * @internal\n * @param isRestoringFactory - Produces the restoration signal for this injector.\n * @returns The provider that makes the restoration state injectable.\n */\nexport function provideIsRestoring(\n isRestoringFactory: () => Signal<boolean>,\n): Provider {\n return {\n provide: IS_RESTORING,\n useFactory: isRestoringFactory,\n }\n}\n"],"mappings":";;;;;AAWA,IAAM,eAAe,IAAI,eAAe,IAAI,EAC1C,eAAe,OAAO,KAAK,CAAC,CAAC,WAAW,EAC1C,CAAC;;;;;;;;AASD,SAAgB,oBAAoB;CAClC,IAAI,OAAO,cAAc,eAAe,WACtC,yBAAyB,iBAAiB;CAE5C,OAAO,OAAO,YAAY;AAC5B;;;;;;;;AASA,SAAgB,mBACd,oBACU;CACV,OAAO;EACL,SAAS;EACT,YAAY;CACd;AACF"}
@@ -17,9 +17,57 @@ export type MutationStateOptions<TResult = MutationState, TMutation extends Muta
17
17
  select?: (mutation: TMutation) => TResult;
18
18
  };
19
19
  /**
20
- * Injects a signal that tracks the state of all mutations.
21
- * @param options - A function that returns mutation state options.
22
- * @returns The signal that tracks the state of all mutations.
20
+ * Injects a signal that gives you access to all mutations in the `MutationCache`. You can pass `filters`
21
+ * ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation state.
22
+ * @param options - A function returning the `filters` to narrow down matched mutations, and an optional
23
+ * `select` to transform the mutation state. Similar to `computed` from Angular, this function runs in the
24
+ * reactive context, so signals read inside it re-narrow the matched mutations.
25
+ * @returns A `Signal` with an Array of whatever `select` returns for each matching mutation.
26
+ * @example
27
+ * Get all variables of all running mutations:
28
+ * ```angular-ts
29
+ * @Component({
30
+ * selector: 'pending-posts',
31
+ * template: `{{ pendingVariables().length }} posts saving...`,
32
+ * })
33
+ * export class PendingPosts {
34
+ * readonly pendingVariables = injectMutationState(() => ({
35
+ * filters: { status: 'pending' },
36
+ * select: (mutation) => mutation.state.variables,
37
+ * }))
38
+ * }
39
+ * ```
40
+ * @example
41
+ * Get all data for specific mutations via the `mutationKey`:
42
+ * ```angular-ts
43
+ * const mutationKey = ['posts']
44
+ *
45
+ * @Component({
46
+ * selector: 'posts',
47
+ * template: `
48
+ * <button (click)="createPost()">
49
+ * Create post ({{ savedPosts().length }} saved so far)
50
+ * </button>
51
+ * `,
52
+ * })
53
+ * export class Posts {
54
+ * // Some mutation that we want to get the state for
55
+ * readonly createPostMutation = injectMutation(() => ({
56
+ * mutationKey,
57
+ * mutationFn: createPosts,
58
+ * }))
59
+ *
60
+ * readonly savedPosts = injectMutationState(() => ({
61
+ * // this mutation key needs to match the mutation key of the given mutation (see above)
62
+ * filters: { mutationKey, status: 'success' },
63
+ * select: (mutation) => mutation.state.data,
64
+ * }))
65
+ *
66
+ * createPost() {
67
+ * this.createPostMutation.mutate(['New Post'])
68
+ * }
69
+ * }
70
+ * ```
23
71
  */
24
72
  export declare function injectMutationState<TResult = MutationState, TMutation extends Mutation<any, any, any, any> = MutationTypeFromResult<TResult>>(options?: () => MutationStateOptions<TResult, TMutation>): Signal<Array<TResult>>;
25
73
  export {};
@@ -12,9 +12,57 @@ function getResult(mutationCache, options) {
12
12
  return mutationCache.findAll(options.filters).map((mutation) => options.select ? options.select(mutation) : mutation.state);
13
13
  }
14
14
  /**
15
- * Injects a signal that tracks the state of all mutations.
16
- * @param options - A function that returns mutation state options.
17
- * @returns The signal that tracks the state of all mutations.
15
+ * Injects a signal that gives you access to all mutations in the `MutationCache`. You can pass `filters`
16
+ * ({@link MutationFilters}) to narrow down your mutations, and `select` to transform the mutation state.
17
+ * @param options - A function returning the `filters` to narrow down matched mutations, and an optional
18
+ * `select` to transform the mutation state. Similar to `computed` from Angular, this function runs in the
19
+ * reactive context, so signals read inside it re-narrow the matched mutations.
20
+ * @returns A `Signal` with an Array of whatever `select` returns for each matching mutation.
21
+ * @example
22
+ * Get all variables of all running mutations:
23
+ * ```angular-ts
24
+ * @Component({
25
+ * selector: 'pending-posts',
26
+ * template: `{{ pendingVariables().length }} posts saving...`,
27
+ * })
28
+ * export class PendingPosts {
29
+ * readonly pendingVariables = injectMutationState(() => ({
30
+ * filters: { status: 'pending' },
31
+ * select: (mutation) => mutation.state.variables,
32
+ * }))
33
+ * }
34
+ * ```
35
+ * @example
36
+ * Get all data for specific mutations via the `mutationKey`:
37
+ * ```angular-ts
38
+ * const mutationKey = ['posts']
39
+ *
40
+ * @Component({
41
+ * selector: 'posts',
42
+ * template: `
43
+ * <button (click)="createPost()">
44
+ * Create post ({{ savedPosts().length }} saved so far)
45
+ * </button>
46
+ * `,
47
+ * })
48
+ * export class Posts {
49
+ * // Some mutation that we want to get the state for
50
+ * readonly createPostMutation = injectMutation(() => ({
51
+ * mutationKey,
52
+ * mutationFn: createPosts,
53
+ * }))
54
+ *
55
+ * readonly savedPosts = injectMutationState(() => ({
56
+ * // this mutation key needs to match the mutation key of the given mutation (see above)
57
+ * filters: { mutationKey, status: 'success' },
58
+ * select: (mutation) => mutation.state.data,
59
+ * }))
60
+ *
61
+ * createPost() {
62
+ * this.createPostMutation.mutate(['New Post'])
63
+ * }
64
+ * }
65
+ * ```
18
66
  */
19
67
  function injectMutationState(options = () => ({})) {
20
68
  if (typeof ngDevMode === "undefined" || ngDevMode) assertInInjectionContext(injectMutationState);