What is the process for making a signal "Stable" so that it can be emitted by an Observable...

Discussão em 'Angular' iniciado por Ole, Fevereiro 12, 2025.

  1. Ole

    Ole Guest

    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);
    }

    Continue reading...

Compartilhe esta Página