@@ -83,14 +83,6 @@ export function injectMutation<
8383 }
8484 } )
8585
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-
9486 /**
9587 * Signal that contains result set by subscriber
9688 */
@@ -101,44 +93,44 @@ export function injectMutation<
10193 TContext
10294 > | null > ( null )
10395
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 ( )
108101
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+ } )
117126
118127 effect (
119128 ( ) => {
120- // observer.trackResult is not used as this optimization is not needed for Angular
121129 const observer = observerSignal ( )
130+ const observerOptions = optionsSignal ( )
122131
123132 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 )
142134 } )
143135 } ,
144136 {
0 commit comments