@tanstack/angular-query-experimental 5.84.0 → 5.84.2

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.
Files changed (71) hide show
  1. package/{dist/index.d.ts → index.d.ts} +1 -1
  2. package/{dist/inject-mutation.d.ts → inject-mutation.d.ts} +1 -2
  3. package/inject-mutation.mjs.map +1 -0
  4. package/{dist/mutation-options.d.ts → mutation-options.d.ts} +4 -8
  5. package/mutation-options.mjs.map +1 -0
  6. package/package.json +5 -41
  7. package/{dist/types.d.ts → types.d.ts} +3 -1
  8. package/dist/inject-mutation.mjs.map +0 -1
  9. package/dist/mutation-options.mjs.map +0 -1
  10. package/src/create-base-query.ts +0 -142
  11. package/src/index.ts +0 -64
  12. package/src/infinite-query-options.ts +0 -187
  13. package/src/inject-infinite-query.ts +0 -129
  14. package/src/inject-is-fetching.ts +0 -66
  15. package/src/inject-is-mutating.ts +0 -65
  16. package/src/inject-is-restoring.ts +0 -52
  17. package/src/inject-mutation-state.ts +0 -125
  18. package/src/inject-mutation.ts +0 -169
  19. package/src/inject-queries.ts +0 -271
  20. package/src/inject-query-client.ts +0 -23
  21. package/src/inject-query.ts +0 -230
  22. package/src/mutation-options.ts +0 -60
  23. package/src/providers.ts +0 -372
  24. package/src/query-options.ts +0 -178
  25. package/src/signal-proxy.ts +0 -46
  26. package/src/types.ts +0 -309
  27. package/src/util/is-dev-mode/is-dev-mode.ts +0 -3
  28. /package/{dist/create-base-query.d.ts → create-base-query.d.ts} +0 -0
  29. /package/{dist/create-base-query.mjs → create-base-query.mjs} +0 -0
  30. /package/{dist/create-base-query.mjs.map → create-base-query.mjs.map} +0 -0
  31. /package/{dist/index.mjs → index.mjs} +0 -0
  32. /package/{dist/index.mjs.map → index.mjs.map} +0 -0
  33. /package/{dist/infinite-query-options.d.ts → infinite-query-options.d.ts} +0 -0
  34. /package/{dist/infinite-query-options.mjs → infinite-query-options.mjs} +0 -0
  35. /package/{dist/infinite-query-options.mjs.map → infinite-query-options.mjs.map} +0 -0
  36. /package/{dist/inject-infinite-query.d.ts → inject-infinite-query.d.ts} +0 -0
  37. /package/{dist/inject-infinite-query.mjs → inject-infinite-query.mjs} +0 -0
  38. /package/{dist/inject-infinite-query.mjs.map → inject-infinite-query.mjs.map} +0 -0
  39. /package/{dist/inject-is-fetching.d.ts → inject-is-fetching.d.ts} +0 -0
  40. /package/{dist/inject-is-fetching.mjs → inject-is-fetching.mjs} +0 -0
  41. /package/{dist/inject-is-fetching.mjs.map → inject-is-fetching.mjs.map} +0 -0
  42. /package/{dist/inject-is-mutating.d.ts → inject-is-mutating.d.ts} +0 -0
  43. /package/{dist/inject-is-mutating.mjs → inject-is-mutating.mjs} +0 -0
  44. /package/{dist/inject-is-mutating.mjs.map → inject-is-mutating.mjs.map} +0 -0
  45. /package/{dist/inject-is-restoring.d.ts → inject-is-restoring.d.ts} +0 -0
  46. /package/{dist/inject-is-restoring.mjs → inject-is-restoring.mjs} +0 -0
  47. /package/{dist/inject-is-restoring.mjs.map → inject-is-restoring.mjs.map} +0 -0
  48. /package/{dist/inject-mutation-state.d.ts → inject-mutation-state.d.ts} +0 -0
  49. /package/{dist/inject-mutation-state.mjs → inject-mutation-state.mjs} +0 -0
  50. /package/{dist/inject-mutation-state.mjs.map → inject-mutation-state.mjs.map} +0 -0
  51. /package/{dist/inject-mutation.mjs → inject-mutation.mjs} +0 -0
  52. /package/{dist/inject-queries.d.ts → inject-queries.d.ts} +0 -0
  53. /package/{dist/inject-queries.mjs → inject-queries.mjs} +0 -0
  54. /package/{dist/inject-queries.mjs.map → inject-queries.mjs.map} +0 -0
  55. /package/{dist/inject-query-client.d.ts → inject-query-client.d.ts} +0 -0
  56. /package/{dist/inject-query-client.mjs → inject-query-client.mjs} +0 -0
  57. /package/{dist/inject-query-client.mjs.map → inject-query-client.mjs.map} +0 -0
  58. /package/{dist/inject-query.d.ts → inject-query.d.ts} +0 -0
  59. /package/{dist/inject-query.mjs → inject-query.mjs} +0 -0
  60. /package/{dist/inject-query.mjs.map → inject-query.mjs.map} +0 -0
  61. /package/{dist/mutation-options.mjs → mutation-options.mjs} +0 -0
  62. /package/{dist/providers.d.ts → providers.d.ts} +0 -0
  63. /package/{dist/providers.mjs → providers.mjs} +0 -0
  64. /package/{dist/providers.mjs.map → providers.mjs.map} +0 -0
  65. /package/{dist/query-options.d.ts → query-options.d.ts} +0 -0
  66. /package/{dist/query-options.mjs → query-options.mjs} +0 -0
  67. /package/{dist/query-options.mjs.map → query-options.mjs.map} +0 -0
  68. /package/{dist/signal-proxy.d.ts → signal-proxy.d.ts} +0 -0
  69. /package/{dist/signal-proxy.mjs → signal-proxy.mjs} +0 -0
  70. /package/{dist/signal-proxy.mjs.map → signal-proxy.mjs.map} +0 -0
  71. /package/{dist/util → util}/is-dev-mode/is-dev-mode.d.ts +0 -0
@@ -1,129 +0,0 @@
1
- import { InfiniteQueryObserver } from '@tanstack/query-core'
2
- import {
3
- Injector,
4
- assertInInjectionContext,
5
- inject,
6
- runInInjectionContext,
7
- } from '@angular/core'
8
- import { createBaseQuery } from './create-base-query'
9
- import type {
10
- DefaultError,
11
- InfiniteData,
12
- QueryKey,
13
- QueryObserver,
14
- } from '@tanstack/query-core'
15
- import type {
16
- CreateInfiniteQueryOptions,
17
- CreateInfiniteQueryResult,
18
- DefinedCreateInfiniteQueryResult,
19
- } from './types'
20
- import type {
21
- DefinedInitialDataInfiniteOptions,
22
- UndefinedInitialDataInfiniteOptions,
23
- } from './infinite-query-options'
24
-
25
- export interface InjectInfiniteQueryOptions {
26
- /**
27
- * The `Injector` in which to create the infinite query.
28
- *
29
- * If this is not provided, the current injection context will be used instead (via `inject`).
30
- */
31
- injector?: Injector
32
- }
33
-
34
- /**
35
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
36
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
37
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
38
- * @param options - Additional configuration.
39
- * @returns The infinite query result.
40
- * @public
41
- */
42
- export function injectInfiniteQuery<
43
- TQueryFnData,
44
- TError = DefaultError,
45
- TData = InfiniteData<TQueryFnData>,
46
- TQueryKey extends QueryKey = QueryKey,
47
- TPageParam = unknown,
48
- >(
49
- injectInfiniteQueryFn: () => DefinedInitialDataInfiniteOptions<
50
- TQueryFnData,
51
- TError,
52
- TData,
53
- TQueryKey,
54
- TPageParam
55
- >,
56
- options?: InjectInfiniteQueryOptions,
57
- ): DefinedCreateInfiniteQueryResult<TData, TError>
58
-
59
- /**
60
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
61
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
62
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
63
- * @param options - Additional configuration.
64
- * @returns The infinite query result.
65
- * @public
66
- */
67
- export function injectInfiniteQuery<
68
- TQueryFnData,
69
- TError = DefaultError,
70
- TData = InfiniteData<TQueryFnData>,
71
- TQueryKey extends QueryKey = QueryKey,
72
- TPageParam = unknown,
73
- >(
74
- injectInfiniteQueryFn: () => UndefinedInitialDataInfiniteOptions<
75
- TQueryFnData,
76
- TError,
77
- TData,
78
- TQueryKey,
79
- TPageParam
80
- >,
81
- options?: InjectInfiniteQueryOptions,
82
- ): CreateInfiniteQueryResult<TData, TError>
83
-
84
- /**
85
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
86
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
87
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
88
- * @param options - Additional configuration.
89
- * @returns The infinite query result.
90
- * @public
91
- */
92
- export function injectInfiniteQuery<
93
- TQueryFnData,
94
- TError = DefaultError,
95
- TData = InfiniteData<TQueryFnData>,
96
- TQueryKey extends QueryKey = QueryKey,
97
- TPageParam = unknown,
98
- >(
99
- injectInfiniteQueryFn: () => CreateInfiniteQueryOptions<
100
- TQueryFnData,
101
- TError,
102
- TData,
103
- TQueryKey,
104
- TPageParam
105
- >,
106
- options?: InjectInfiniteQueryOptions,
107
- ): CreateInfiniteQueryResult<TData, TError>
108
-
109
- /**
110
- * Injects an infinite query: a declarative dependency on an asynchronous source of data that is tied to a unique key.
111
- * Infinite queries can additively "load more" data onto an existing set of data or "infinite scroll"
112
- * @param injectInfiniteQueryFn - A function that returns infinite query options.
113
- * @param options - Additional configuration.
114
- * @returns The infinite query result.
115
- * @public
116
- */
117
- export function injectInfiniteQuery(
118
- injectInfiniteQueryFn: () => CreateInfiniteQueryOptions,
119
- options?: InjectInfiniteQueryOptions,
120
- ) {
121
- !options?.injector && assertInInjectionContext(injectInfiniteQuery)
122
- const injector = options?.injector ?? inject(Injector)
123
- return runInInjectionContext(injector, () =>
124
- createBaseQuery(
125
- injectInfiniteQueryFn,
126
- InfiniteQueryObserver as typeof QueryObserver,
127
- ),
128
- )
129
- }
@@ -1,66 +0,0 @@
1
- import {
2
- DestroyRef,
3
- Injector,
4
- NgZone,
5
- assertInInjectionContext,
6
- inject,
7
- signal,
8
- } from '@angular/core'
9
- import { QueryClient, notifyManager } from '@tanstack/query-core'
10
- import type { QueryFilters } from '@tanstack/query-core'
11
- import type { Signal } from '@angular/core'
12
-
13
- export interface InjectIsFetchingOptions {
14
- /**
15
- * The `Injector` in which to create the isFetching signal.
16
- *
17
- * If this is not provided, the current injection context will be used instead (via `inject`).
18
- */
19
- injector?: Injector
20
- }
21
-
22
- /**
23
- * Injects a signal that tracks the number of queries that your application is loading or
24
- * fetching in the background.
25
- *
26
- * Can be used for app-wide loading indicators
27
- * @param filters - The filters to apply to the query.
28
- * @param options - Additional configuration
29
- * @returns signal with number of loading or fetching queries.
30
- * @public
31
- */
32
- export function injectIsFetching(
33
- filters?: QueryFilters,
34
- options?: InjectIsFetchingOptions,
35
- ): Signal<number> {
36
- !options?.injector && assertInInjectionContext(injectIsFetching)
37
- const injector = options?.injector ?? inject(Injector)
38
- const destroyRef = injector.get(DestroyRef)
39
- const ngZone = injector.get(NgZone)
40
- const queryClient = injector.get(QueryClient)
41
-
42
- const cache = queryClient.getQueryCache()
43
- // isFetching is the prev value initialized on mount *
44
- let isFetching = queryClient.isFetching(filters)
45
-
46
- const result = signal(isFetching)
47
-
48
- const unsubscribe = ngZone.runOutsideAngular(() =>
49
- cache.subscribe(
50
- notifyManager.batchCalls(() => {
51
- const newIsFetching = queryClient.isFetching(filters)
52
- if (isFetching !== newIsFetching) {
53
- // * and update with each change
54
- isFetching = newIsFetching
55
- ngZone.run(() => {
56
- result.set(isFetching)
57
- })
58
- }
59
- }),
60
- ),
61
- )
62
-
63
- destroyRef.onDestroy(unsubscribe)
64
-
65
- return result
66
- }
@@ -1,65 +0,0 @@
1
- import {
2
- DestroyRef,
3
- Injector,
4
- NgZone,
5
- assertInInjectionContext,
6
- inject,
7
- signal,
8
- } from '@angular/core'
9
- import { QueryClient, notifyManager } from '@tanstack/query-core'
10
- import type { MutationFilters } from '@tanstack/query-core'
11
- import type { Signal } from '@angular/core'
12
-
13
- export interface InjectIsMutatingOptions {
14
- /**
15
- * The `Injector` in which to create the isMutating signal.
16
- *
17
- * If this is not provided, the current injection context will be used instead (via `inject`).
18
- */
19
- injector?: Injector
20
- }
21
-
22
- /**
23
- * Injects a signal that tracks the number of mutations that your application is fetching.
24
- *
25
- * Can be used for app-wide loading indicators
26
- * @param filters - The filters to apply to the query.
27
- * @param options - Additional configuration
28
- * @returns signal with number of fetching mutations.
29
- * @public
30
- */
31
- export function injectIsMutating(
32
- filters?: MutationFilters,
33
- options?: InjectIsMutatingOptions,
34
- ): Signal<number> {
35
- !options?.injector && assertInInjectionContext(injectIsMutating)
36
- const injector = options?.injector ?? inject(Injector)
37
- const destroyRef = injector.get(DestroyRef)
38
- const ngZone = injector.get(NgZone)
39
- const queryClient = injector.get(QueryClient)
40
-
41
- const cache = queryClient.getMutationCache()
42
- // isMutating is the prev value initialized on mount *
43
- let isMutating = queryClient.isMutating(filters)
44
-
45
- const result = signal(isMutating)
46
-
47
- const unsubscribe = ngZone.runOutsideAngular(() =>
48
- cache.subscribe(
49
- notifyManager.batchCalls(() => {
50
- const newIsMutating = queryClient.isMutating(filters)
51
- if (isMutating !== newIsMutating) {
52
- // * and update with each change
53
- isMutating = newIsMutating
54
- ngZone.run(() => {
55
- result.set(isMutating)
56
- })
57
- }
58
- }),
59
- ),
60
- )
61
-
62
- destroyRef.onDestroy(unsubscribe)
63
-
64
- return result
65
- }
@@ -1,52 +0,0 @@
1
- import {
2
- InjectionToken,
3
- Injector,
4
- assertInInjectionContext,
5
- inject,
6
- signal,
7
- } from '@angular/core'
8
- import type { Provider, Signal } from '@angular/core'
9
-
10
- const IS_RESTORING = new InjectionToken(
11
- typeof ngDevMode === 'undefined' || ngDevMode
12
- ? 'TANSTACK_QUERY_IS_RESTORING'
13
- : '',
14
- {
15
- // Default value when not provided
16
- factory: () => signal(false).asReadonly(),
17
- },
18
- )
19
-
20
- /**
21
- * The `Injector` in which to create the isRestoring signal.
22
- *
23
- * If this is not provided, the current injection context will be used instead (via `inject`).
24
- */
25
- interface InjectIsRestoringOptions {
26
- injector?: Injector
27
- }
28
-
29
- /**
30
- * Injects a signal that tracks whether a restore is currently in progress. {@link injectQuery} and friends also check this internally to avoid race conditions between the restore and initializing queries.
31
- * @param options - Options for injectIsRestoring.
32
- * @returns signal with boolean that indicates whether a restore is in progress.
33
- * @public
34
- */
35
- export function injectIsRestoring(options?: InjectIsRestoringOptions) {
36
- !options?.injector && assertInInjectionContext(injectIsRestoring)
37
- const injector = options?.injector ?? inject(Injector)
38
- return injector.get(IS_RESTORING)
39
- }
40
-
41
- /**
42
- * Used by TanStack Query Angular persist client plugin to provide the signal that tracks the restore state
43
- * @param isRestoring - a readonly signal that returns a boolean
44
- * @returns Provider for the `isRestoring` signal
45
- * @public
46
- */
47
- export function provideIsRestoring(isRestoring: Signal<boolean>): Provider {
48
- return {
49
- provide: IS_RESTORING,
50
- useValue: isRestoring,
51
- }
52
- }
@@ -1,125 +0,0 @@
1
- import {
2
- DestroyRef,
3
- Injector,
4
- NgZone,
5
- assertInInjectionContext,
6
- computed,
7
- inject,
8
- signal,
9
- } from '@angular/core'
10
- import {
11
- QueryClient,
12
- notifyManager,
13
- replaceEqualDeep,
14
- } from '@tanstack/query-core'
15
- import type { Signal } from '@angular/core'
16
- import type {
17
- Mutation,
18
- MutationCache,
19
- MutationFilters,
20
- MutationState,
21
- } from '@tanstack/query-core'
22
-
23
- type MutationStateOptions<TResult = MutationState> = {
24
- filters?: MutationFilters
25
- select?: (mutation: Mutation) => TResult
26
- }
27
-
28
- /**
29
- *
30
- * @param mutationCache
31
- * @param options
32
- */
33
- function getResult<TResult = MutationState>(
34
- mutationCache: MutationCache,
35
- options: MutationStateOptions<TResult>,
36
- ): Array<TResult> {
37
- return mutationCache
38
- .findAll(options.filters)
39
- .map(
40
- (mutation): TResult =>
41
- (options.select ? options.select(mutation) : mutation.state) as TResult,
42
- )
43
- }
44
-
45
- /**
46
- * @public
47
- */
48
- export interface InjectMutationStateOptions {
49
- /**
50
- * The `Injector` in which to create the mutation state signal.
51
- *
52
- * If this is not provided, the current injection context will be used instead (via `inject`).
53
- */
54
- injector?: Injector
55
- }
56
-
57
- /**
58
- * Injects a signal that tracks the state of all mutations.
59
- * @param injectMutationStateFn - A function that returns mutation state options.
60
- * @param options - The Angular injector to use.
61
- * @returns The signal that tracks the state of all mutations.
62
- * @public
63
- */
64
- export function injectMutationState<TResult = MutationState>(
65
- injectMutationStateFn: () => MutationStateOptions<TResult> = () => ({}),
66
- options?: InjectMutationStateOptions,
67
- ): Signal<Array<TResult>> {
68
- !options?.injector && assertInInjectionContext(injectMutationState)
69
- const injector = options?.injector ?? inject(Injector)
70
- const destroyRef = injector.get(DestroyRef)
71
- const ngZone = injector.get(NgZone)
72
- const queryClient = injector.get(QueryClient)
73
- const mutationCache = queryClient.getMutationCache()
74
-
75
- /**
76
- * Computed signal that gets result from mutation cache based on passed options
77
- * First element is the result, second element is the time when the result was set
78
- */
79
- const resultFromOptionsSignal = computed(() => {
80
- return [
81
- getResult(mutationCache, injectMutationStateFn()),
82
- performance.now(),
83
- ] as const
84
- })
85
-
86
- /**
87
- * Signal that contains result set by subscriber
88
- * First element is the result, second element is the time when the result was set
89
- */
90
- const resultFromSubscriberSignal = signal<[Array<TResult>, number] | null>(
91
- null,
92
- )
93
-
94
- /**
95
- * Returns the last result by either subscriber or options
96
- */
97
- const effectiveResultSignal = computed(() => {
98
- const optionsResult = resultFromOptionsSignal()
99
- const subscriberResult = resultFromSubscriberSignal()
100
- return subscriberResult && subscriberResult[1] > optionsResult[1]
101
- ? subscriberResult[0]
102
- : optionsResult[0]
103
- })
104
-
105
- const unsubscribe = ngZone.runOutsideAngular(() =>
106
- mutationCache.subscribe(
107
- notifyManager.batchCalls(() => {
108
- const [lastResult] = effectiveResultSignal()
109
- const nextResult = replaceEqualDeep(
110
- lastResult,
111
- getResult(mutationCache, injectMutationStateFn()),
112
- )
113
- if (lastResult !== nextResult) {
114
- ngZone.run(() => {
115
- resultFromSubscriberSignal.set([nextResult, performance.now()])
116
- })
117
- }
118
- }),
119
- ),
120
- )
121
-
122
- destroyRef.onDestroy(unsubscribe)
123
-
124
- return effectiveResultSignal
125
- }
@@ -1,169 +0,0 @@
1
- import {
2
- DestroyRef,
3
- Injector,
4
- NgZone,
5
- assertInInjectionContext,
6
- computed,
7
- effect,
8
- inject,
9
- signal,
10
- untracked,
11
- } from '@angular/core'
12
- import {
13
- MutationObserver,
14
- QueryClient,
15
- noop,
16
- notifyManager,
17
- shouldThrowError,
18
- } from '@tanstack/query-core'
19
- import { signalProxy } from './signal-proxy'
20
- import type { DefaultError, MutationObserverResult } from '@tanstack/query-core'
21
- import type { CreateMutateFunction, CreateMutationResult } from './types'
22
- import type { CreateMutationOptions } from './mutation-options'
23
-
24
- export interface InjectMutationOptions {
25
- /**
26
- * The `Injector` in which to create the mutation.
27
- *
28
- * If this is not provided, the current injection context will be used instead (via `inject`).
29
- */
30
- injector?: Injector
31
- }
32
-
33
- /**
34
- * Injects a mutation: an imperative function that can be invoked which typically performs server side effects.
35
- *
36
- * Unlike queries, mutations are not run automatically.
37
- * @param injectMutationFn - A function that returns mutation options.
38
- * @param options - Additional configuration
39
- * @returns The mutation.
40
- * @public
41
- */
42
- export function injectMutation<
43
- TData = unknown,
44
- TError = DefaultError,
45
- TVariables = void,
46
- TContext = unknown,
47
- >(
48
- injectMutationFn: () => CreateMutationOptions<
49
- TData,
50
- TError,
51
- TVariables,
52
- TContext
53
- >,
54
- options?: InjectMutationOptions,
55
- ): CreateMutationResult<TData, TError, TVariables, TContext> {
56
- !options?.injector && assertInInjectionContext(injectMutation)
57
- const injector = options?.injector ?? inject(Injector)
58
- const destroyRef = injector.get(DestroyRef)
59
- const ngZone = injector.get(NgZone)
60
- const queryClient = injector.get(QueryClient)
61
-
62
- /**
63
- * computed() is used so signals can be inserted into the options
64
- * making it reactive. Wrapping options in a function ensures embedded expressions
65
- * are preserved and can keep being applied after signal changes
66
- */
67
- const optionsSignal = computed(injectMutationFn)
68
-
69
- const observerSignal = (() => {
70
- let instance: MutationObserver<TData, TError, TVariables, TContext> | null =
71
- null
72
-
73
- return computed(() => {
74
- return (instance ||= new MutationObserver(queryClient, optionsSignal()))
75
- })
76
- })()
77
-
78
- const mutateFnSignal = computed<
79
- CreateMutateFunction<TData, TError, TVariables, TContext>
80
- >(() => {
81
- const observer = observerSignal()
82
- return (variables, mutateOptions) => {
83
- observer.mutate(variables, mutateOptions).catch(noop)
84
- }
85
- })
86
-
87
- /**
88
- * Computed signal that gets result from mutation cache based on passed options
89
- */
90
- const resultFromInitialOptionsSignal = computed(() => {
91
- const observer = observerSignal()
92
- return observer.getCurrentResult()
93
- })
94
-
95
- /**
96
- * Signal that contains result set by subscriber
97
- */
98
- const resultFromSubscriberSignal = signal<MutationObserverResult<
99
- TData,
100
- TError,
101
- TVariables,
102
- TContext
103
- > | null>(null)
104
-
105
- effect(
106
- () => {
107
- const observer = observerSignal()
108
- const observerOptions = optionsSignal()
109
-
110
- untracked(() => {
111
- observer.setOptions(observerOptions)
112
- })
113
- },
114
- {
115
- injector,
116
- },
117
- )
118
-
119
- effect(
120
- () => {
121
- // observer.trackResult is not used as this optimization is not needed for Angular
122
- const observer = observerSignal()
123
-
124
- untracked(() => {
125
- const unsubscribe = ngZone.runOutsideAngular(() =>
126
- observer.subscribe(
127
- notifyManager.batchCalls((state) => {
128
- ngZone.run(() => {
129
- if (
130
- state.isError &&
131
- shouldThrowError(observer.options.throwOnError, [state.error])
132
- ) {
133
- ngZone.onError.emit(state.error)
134
- throw state.error
135
- }
136
-
137
- resultFromSubscriberSignal.set(state)
138
- })
139
- }),
140
- ),
141
- )
142
- destroyRef.onDestroy(unsubscribe)
143
- })
144
- },
145
- {
146
- injector,
147
- },
148
- )
149
-
150
- const resultSignal = computed(() => {
151
- const resultFromSubscriber = resultFromSubscriberSignal()
152
- const resultFromInitialOptions = resultFromInitialOptionsSignal()
153
-
154
- const result = resultFromSubscriber ?? resultFromInitialOptions
155
-
156
- return {
157
- ...result,
158
- mutate: mutateFnSignal(),
159
- mutateAsync: result.mutate,
160
- }
161
- })
162
-
163
- return signalProxy(resultSignal) as CreateMutationResult<
164
- TData,
165
- TError,
166
- TVariables,
167
- TContext
168
- >
169
- }