@tanstack/angular-query-experimental 5.72.2 → 5.73.3

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.
@@ -18,6 +18,11 @@ type MutationStateOptions<TResult = MutationState> = {
18
18
  select?: (mutation: Mutation) => TResult
19
19
  }
20
20
 
21
+ /**
22
+ *
23
+ * @param mutationCache
24
+ * @param options
25
+ */
21
26
  function getResult<TResult = MutationState>(
22
27
  mutationCache: MutationCache,
23
28
  options: MutationStateOptions<TResult>,
@@ -34,18 +39,23 @@ function getResult<TResult = MutationState>(
34
39
  * @public
35
40
  */
36
41
  export interface InjectMutationStateOptions {
42
+ /**
43
+ * The `Injector` in which to create the mutation state signal.
44
+ *
45
+ * If this is not provided, the current injection context will be used instead (via `inject`).
46
+ */
37
47
  injector?: Injector
38
48
  }
39
49
 
40
50
  /**
41
51
  * Injects a signal that tracks the state of all mutations.
42
- * @param mutationStateOptionsFn - A function that returns mutation state options.
52
+ * @param injectMutationStateFn - A function that returns mutation state options.
43
53
  * @param options - The Angular injector to use.
44
54
  * @returns The signal that tracks the state of all mutations.
45
55
  * @public
46
56
  */
47
57
  export function injectMutationState<TResult = MutationState>(
48
- mutationStateOptionsFn: () => MutationStateOptions<TResult> = () => ({}),
58
+ injectMutationStateFn: () => MutationStateOptions<TResult> = () => ({}),
49
59
  options?: InjectMutationStateOptions,
50
60
  ): Signal<Array<TResult>> {
51
61
  return assertInjector(injectMutationState, options?.injector, () => {
@@ -61,7 +71,7 @@ export function injectMutationState<TResult = MutationState>(
61
71
  */
62
72
  const resultFromOptionsSignal = computed(() => {
63
73
  return [
64
- getResult(mutationCache, mutationStateOptionsFn()),
74
+ getResult(mutationCache, injectMutationStateFn()),
65
75
  performance.now(),
66
76
  ] as const
67
77
  })
@@ -91,7 +101,7 @@ export function injectMutationState<TResult = MutationState>(
91
101
  const [lastResult] = effectiveResultSignal()
92
102
  const nextResult = replaceEqualDeep(
93
103
  lastResult,
94
- getResult(mutationCache, mutationStateOptionsFn()),
104
+ getResult(mutationCache, injectMutationStateFn()),
95
105
  )
96
106
  if (lastResult !== nextResult) {
97
107
  ngZone.run(() => {
@@ -20,12 +20,21 @@ import type { DefaultError, MutationObserverResult } from '@tanstack/query-core'
20
20
  import type { CreateMutateFunction, CreateMutationResult } from './types'
21
21
  import type { CreateMutationOptions } from './mutation-options'
22
22
 
23
+ export interface InjectMutationOptions {
24
+ /**
25
+ * The `Injector` in which to create the mutation.
26
+ *
27
+ * If this is not provided, the current injection context will be used instead (via `inject`).
28
+ */
29
+ injector?: Injector
30
+ }
31
+
23
32
  /**
24
33
  * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
25
34
  *
26
35
  * Unlike queries, mutations are not run automatically.
27
- * @param optionsFn - A function that returns mutation options.
28
- * @param injector - The Angular injector to use.
36
+ * @param injectMutationFn - A function that returns mutation options.
37
+ * @param options - Additional configuration
29
38
  * @returns The mutation.
30
39
  * @public
31
40
  */
@@ -35,10 +44,15 @@ export function injectMutation<
35
44
  TVariables = void,
36
45
  TContext = unknown,
37
46
  >(
38
- optionsFn: () => CreateMutationOptions<TData, TError, TVariables, TContext>,
39
- injector?: Injector,
47
+ injectMutationFn: () => CreateMutationOptions<
48
+ TData,
49
+ TError,
50
+ TVariables,
51
+ TContext
52
+ >,
53
+ options?: InjectMutationOptions,
40
54
  ): CreateMutationResult<TData, TError, TVariables, TContext> {
41
- return assertInjector(injectMutation, injector, () => {
55
+ return assertInjector(injectMutation, options?.injector, () => {
42
56
  const destroyRef = inject(DestroyRef)
43
57
  const ngZone = inject(NgZone)
44
58
  const queryClient = inject(QueryClient)
@@ -48,7 +62,7 @@ export function injectMutation<
48
62
  * making it reactive. Wrapping options in a function ensures embedded expressions
49
63
  * are preserved and can keep being applied after signal changes
50
64
  */
51
- const optionsSignal = computed(optionsFn)
65
+ const optionsSignal = computed(injectMutationFn)
52
66
 
53
67
  const observerSignal = (() => {
54
68
  let instance: MutationObserver<
@@ -93,14 +107,14 @@ export function injectMutation<
93
107
  effect(
94
108
  () => {
95
109
  const observer = observerSignal()
96
- const options = optionsSignal()
110
+ const observerOptions = optionsSignal()
97
111
 
98
112
  untracked(() => {
99
- observer.setOptions(options)
113
+ observer.setOptions(observerOptions)
100
114
  })
101
115
  },
102
116
  {
103
- injector,
117
+ injector: options?.injector,
104
118
  },
105
119
  )
106
120
 
@@ -133,7 +147,7 @@ export function injectMutation<
133
147
  })
134
148
  },
135
149
  {
136
- injector,
150
+ injector: options?.injector,
137
151
  },
138
152
  )
139
153
 
@@ -197,6 +197,7 @@ export type QueriesResults<
197
197
  * @param root0.queries
198
198
  * @param root0.combine
199
199
  * @param injector
200
+ * @param injector
200
201
  * @public
201
202
  */
202
203
  export function injectQueries<
@@ -13,6 +13,15 @@ import type {
13
13
  UndefinedInitialDataOptions,
14
14
  } from './query-options'
15
15
 
16
+ export interface InjectQueryOptions {
17
+ /**
18
+ * The `Injector` in which to create the query.
19
+ *
20
+ * If this is not provided, the current injection context will be used instead (via `inject`).
21
+ */
22
+ injector?: Injector
23
+ }
24
+
16
25
  /**
17
26
  * Injects a query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
18
27
  *
@@ -44,8 +53,8 @@ import type {
44
53
  * }))
45
54
  * }
46
55
  * ```
47
- * @param optionsFn - A function that returns query options.
48
- * @param injector - The Angular injector to use.
56
+ * @param injectQueryFn - A function that returns query options.
57
+ * @param options - Additional configuration
49
58
  * @returns The query result.
50
59
  * @public
51
60
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
@@ -56,13 +65,13 @@ export function injectQuery<
56
65
  TData = TQueryFnData,
57
66
  TQueryKey extends QueryKey = QueryKey,
58
67
  >(
59
- optionsFn: () => DefinedInitialDataOptions<
68
+ injectQueryFn: () => DefinedInitialDataOptions<
60
69
  TQueryFnData,
61
70
  TError,
62
71
  TData,
63
72
  TQueryKey
64
73
  >,
65
- injector?: Injector,
74
+ options?: InjectQueryOptions,
66
75
  ): DefinedCreateQueryResult<TData, TError>
67
76
 
68
77
  /**
@@ -96,8 +105,8 @@ export function injectQuery<
96
105
  * }))
97
106
  * }
98
107
  * ```
99
- * @param optionsFn - A function that returns query options.
100
- * @param injector - The Angular injector to use.
108
+ * @param injectQueryFn - A function that returns query options.
109
+ * @param options - Additional configuration
101
110
  * @returns The query result.
102
111
  * @public
103
112
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
@@ -108,13 +117,13 @@ export function injectQuery<
108
117
  TData = TQueryFnData,
109
118
  TQueryKey extends QueryKey = QueryKey,
110
119
  >(
111
- optionsFn: () => UndefinedInitialDataOptions<
120
+ injectQueryFn: () => UndefinedInitialDataOptions<
112
121
  TQueryFnData,
113
122
  TError,
114
123
  TData,
115
124
  TQueryKey
116
125
  >,
117
- injector?: Injector,
126
+ options?: InjectQueryOptions,
118
127
  ): CreateQueryResult<TData, TError>
119
128
 
120
129
  /**
@@ -148,8 +157,8 @@ export function injectQuery<
148
157
  * }))
149
158
  * }
150
159
  * ```
151
- * @param optionsFn - A function that returns query options.
152
- * @param injector - The Angular injector to use.
160
+ * @param injectQueryFn - A function that returns query options.
161
+ * @param options - Additional configuration
153
162
  * @returns The query result.
154
163
  * @public
155
164
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
@@ -160,8 +169,13 @@ export function injectQuery<
160
169
  TData = TQueryFnData,
161
170
  TQueryKey extends QueryKey = QueryKey,
162
171
  >(
163
- optionsFn: () => CreateQueryOptions<TQueryFnData, TError, TData, TQueryKey>,
164
- injector?: Injector,
172
+ injectQueryFn: () => CreateQueryOptions<
173
+ TQueryFnData,
174
+ TError,
175
+ TData,
176
+ TQueryKey
177
+ >,
178
+ options?: InjectQueryOptions,
165
179
  ): CreateQueryResult<TData, TError>
166
180
 
167
181
  /**
@@ -195,17 +209,17 @@ export function injectQuery<
195
209
  * }))
196
210
  * }
197
211
  * ```
198
- * @param optionsFn - A function that returns query options.
199
- * @param injector - The Angular injector to use.
212
+ * @param injectQueryFn - A function that returns query options.
213
+ * @param options - Additional configuration
200
214
  * @returns The query result.
201
215
  * @public
202
216
  * @see https://tanstack.com/query/latest/docs/framework/angular/guides/queries
203
217
  */
204
218
  export function injectQuery(
205
- optionsFn: () => CreateQueryOptions,
206
- injector?: Injector,
219
+ injectQueryFn: () => CreateQueryOptions,
220
+ options?: InjectQueryOptions,
207
221
  ) {
208
- return assertInjector(injectQuery, injector, () =>
209
- createBaseQuery(optionsFn, QueryObserver),
222
+ return assertInjector(injectQuery, options?.injector, () =>
223
+ createBaseQuery(injectQueryFn, QueryObserver),
210
224
  ) as unknown as CreateQueryResult
211
225
  }
package/src/providers.ts CHANGED
@@ -233,17 +233,17 @@ export interface DevtoolsOptions {
233
233
  * If you need more control over when devtools are loaded, you can use the `loadDevtools` option. This is particularly useful if you want to load devtools based on environment configurations. For instance, you might have a test environment running in production mode but still require devtools to be available.
234
234
  *
235
235
  * If you need more control over where devtools are rendered, consider `injectDevtoolsPanel`. This allows rendering devtools inside your own devtools for example.
236
- * @param optionsFn - A function that returns `DevtoolsOptions`.
236
+ * @param withDevtoolsFn - A function that returns `DevtoolsOptions`.
237
237
  * @returns A set of providers for use with `provideTanStackQuery`.
238
238
  * @public
239
239
  * @see {@link provideTanStackQuery}
240
240
  * @see {@link DevtoolsOptions}
241
241
  */
242
242
  export function withDevtools(
243
- optionsFn?: () => DevtoolsOptions,
243
+ withDevtoolsFn?: () => DevtoolsOptions,
244
244
  ): DeveloperToolsFeature {
245
245
  let providers: Array<Provider> = []
246
- if (!isDevMode() && !optionsFn) {
246
+ if (!isDevMode() && !withDevtoolsFn) {
247
247
  providers = []
248
248
  } else {
249
249
  providers = [
@@ -258,7 +258,7 @@ export function withDevtools(
258
258
  })
259
259
  const destroyRef = inject(DestroyRef)
260
260
 
261
- const options = computed(() => optionsFn?.() ?? {})
261
+ const options = computed(() => withDevtoolsFn?.() ?? {})
262
262
 
263
263
  let devtools: TanstackQueryDevtools | null = null
264
264
  let el: HTMLElement | null = null
@@ -23,13 +23,11 @@ import {
23
23
  * After assertion, `assertInjector` runs the `runner` function with the guaranteed `Injector`
24
24
  * whether it is the default `Injector` within the current **Injection Context**
25
25
  * or the custom `Injector` that was passed in.
26
- *
27
26
  * @template {() => any} Runner - Runner is a function that can return anything
28
- * @param {Function} fn - the Function to pass in `assertInInjectionContext`
29
- * @param {Injector | undefined | null} injector - the optional "custom" Injector
30
- * @param {Runner} runner - the runner fn
31
- * @returns {ReturnType<Runner>} result - returns the result of the Runner
32
- *
27
+ * @param fn - the Function to pass in `assertInInjectionContext`
28
+ * @param injector - the optional "custom" Injector
29
+ * @param runner - the runner fn
30
+ * @returns result - returns the result of the Runner
33
31
  * @example
34
32
  * ```ts
35
33
  * function injectValue(injector?: Injector) {
@@ -48,11 +46,9 @@ export function assertInjector<TRunner extends () => any>(
48
46
  * `assertInjector` extends `assertInInjectionContext` with an optional `Injector`
49
47
  * After assertion, `assertInjector` returns a guaranteed `Injector` whether it is the default `Injector`
50
48
  * within the current **Injection Context** or the custom `Injector` that was passed in.
51
- *
52
- * @param {Function} fn - the Function to pass in `assertInInjectionContext`
53
- * @param {Injector | undefined | null} injector - the optional "custom" Injector
49
+ * @param fn - the Function to pass in `assertInInjectionContext`
50
+ * @param injector - the optional "custom" Injector
54
51
  * @returns Injector
55
- *
56
52
  * @example
57
53
  * ```ts
58
54
  * function injectDestroy(injector?: Injector) {
@@ -68,6 +64,12 @@ export function assertInjector(
68
64
  fn: Function,
69
65
  injector: Injector | undefined | null,
70
66
  ): Injector
67
+ /**
68
+ * @param fn - the Function to pass in `assertInInjectionContext`
69
+ * @param injector - the optional "custom" Injector
70
+ * @param runner - the runner fn
71
+ * @returns any
72
+ */
71
73
  export function assertInjector(
72
74
  fn: Function,
73
75
  injector: Injector | undefined | null,