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