In the RxJS Interop documentation for Angular 19 it says:
Unlike Observables, signals never provide a synchronous notification of changes. Even if you update a signal's value multiple times, toObservable will only emit the value after the signal stabilizes.
And it gives this example:
const obs$ = toObservable(mySignal);
obs$.subscribe(value => console.log(value));
mySignal.set(1);
mySignal.set(2);
mySignal.set(3);
In the above case only 3
gets logged.
So how do we "Stabilize" my signal after if we want each set
call to be emitted by the corresponding observable?
Is it enough to always wrap the set in a method call like this and are there any other ways of doing it?
updateMySignal(value: number) {
this.mySignal.set(value);
}
toObservable
is effect
based.
As of v19, effect
run as part of ApplicationRef.tick
for root effect and ahead of the component being checked by CD for "View Effects".
So the observable will emit during CD.
If you need an event to be emitted, use an observable directly and not signals.