How to utilize Angular signals in production enterprise applications

Discussão em 'Angular' iniciado por royneedshelp, Setembro 26, 2024.

  1. royneedshelp

    royneedshelp Guest

    In 'real' Angular code how should I be introducing signals into my data retrieval flows?

    Prior to signals I would code as declaratively as possible so within my component header I may have something like:

    private id$ = <some observable to retrieve a user id from the URL e.g. using ngrx router store>
    public userData$ = this.id$.pipe(switchMap(id => this.userService.getUser(id))


    I'd then bind directly to that observable in my template

    If I want to leverage the benefits of signals it feels like I need to make some compromises, either:

    1. Use the developer preview feature toSignal() - nervous of doing this in a large enterprise application
    2. Lose the declarative nature of my code and subscribe to the userData$ observable in OnInit and move the results into a signal that is then referenced in my template

    Additionally I sometimes have Input() parameters that can change requiring a refresh of the data. If I store those input values in signals then I either have to use toObservable() to get the reactivity to prompt a data refresh; or hack an effect() together to requery the api whenever they change.

    Are others battling with this same decisions, or are there any other patterns out there to bridge the gap between signals and RxJS that do not rely on developer preview features?

    Continue reading...

Compartilhe esta Página