@@ -84,14 +84,6 @@ export function injectMutation<
84
84
}
85
85
} )
86
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
87
/**
96
88
* Signal that contains result set by subscriber
97
89
*/
@@ -102,44 +94,44 @@ export function injectMutation<
102
94
TContext
103
95
> | null > ( null )
104
96
105
- effect (
106
- ( ) => {
107
- const observer = observerSignal ( )
108
- const observerOptions = optionsSignal ( )
97
+ /**
98
+ * Computed signal that gets result from mutation cache based on passed options
99
+ */
100
+ const resultFromInitialOptionsSignal = computed ( ( ) => {
101
+ const observer = observerSignal ( )
109
102
110
- untracked ( ( ) => {
111
- observer . setOptions ( observerOptions )
112
- } )
113
- } ,
114
- {
115
- injector,
116
- } ,
117
- )
103
+ untracked ( ( ) => {
104
+ const unsubscribe = ngZone . runOutsideAngular ( ( ) =>
105
+ // observer.trackResult is not used as this optimization is not needed for Angular
106
+ observer . subscribe (
107
+ notifyManager . batchCalls ( ( state ) => {
108
+ ngZone . run ( ( ) => {
109
+ if (
110
+ state . isError &&
111
+ shouldThrowError ( observer . options . throwOnError , [ state . error ] )
112
+ ) {
113
+ ngZone . onError . emit ( state . error )
114
+ throw state . error
115
+ }
116
+
117
+ resultFromSubscriberSignal . set ( state )
118
+ } )
119
+ } ) ,
120
+ ) ,
121
+ )
122
+ destroyRef . onDestroy ( unsubscribe )
123
+ } )
124
+
125
+ return observer . getCurrentResult ( )
126
+ } )
118
127
119
128
effect (
120
129
( ) => {
121
- // observer.trackResult is not used as this optimization is not needed for Angular
122
130
const observer = observerSignal ( )
131
+ const observerOptions = optionsSignal ( )
123
132
124
133
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 )
134
+ observer . setOptions ( observerOptions )
143
135
} )
144
136
} ,
145
137
{
0 commit comments