File tree Expand file tree Collapse file tree 1 file changed +6
-1
lines changed
packages/core/rxjs-interop/src Expand file tree Collapse file tree 1 file changed +6
-1
lines changed Original file line number Diff line number Diff line change @@ -164,6 +164,8 @@ export function toSignal<T, U = undefined>(
164164 ) ;
165165 }
166166
167+ let destroyUnregisterFn : ( ( ) => void ) | undefined ;
168+
167169 // Note: This code cannot run inside a reactive context (see assertion above). If we'd support
168170 // this, we would subscribe to the observable outside of the current reactive context, avoiding
169171 // that side-effect signal reads/writes are attribute to the current consumer. The current
@@ -180,6 +182,9 @@ export function toSignal<T, U = undefined>(
180182 }
181183 state . set ( { kind : StateKind . Error , error} ) ;
182184 } ,
185+ complete : ( ) => {
186+ destroyUnregisterFn ?.( ) ;
187+ } ,
183188 // Completion of the Observable is meaningless to the signal. Signals don't have a concept of
184189 // "complete".
185190 } ) ;
@@ -193,7 +198,7 @@ export function toSignal<T, U = undefined>(
193198 }
194199
195200 // Unsubscribe when the current context is destroyed, if requested.
196- cleanupRef ?. onDestroy ( sub . unsubscribe . bind ( sub ) ) ;
201+ destroyUnregisterFn = cleanupRef ?. onDestroy ( sub . unsubscribe . bind ( sub ) ) ;
197202
198203 // The actual returned signal is a `computed` of the `State` signal, which maps the various states
199204 // to either values or errors.
You can’t perform that action at this time.
0 commit comments