#Signal-based reactive data services

7 messages · Page 1 of 1 (latest)

swift axle
#

Hello people.

I am trying to architect a new Angular application, and I would like any suggestions on how to utilize the new Signals API to create state management and data services.

I have been using the Data services with rxjs Subjects/BehaviorSubjects pattern for many years successfully, and I would like any info on how to implement something similar using Signals. I understand that I can map observables to Signals and vice-versa, but it seems that this pattern is useful only if you need to adopt signals in an existing project, and cannot afford the effort of re-writing your data/state management.
Maybe I am wrong, but it feels like this isn't the best approach to use Signals.

p.s. I do not want to use any 3d party state management library like ngrx, redux etc

Thanks!

quasi smelt
#

but it seems that this pattern is useful only if you need to adopt signals in an existing project, and cannot afford the effort of re-writing your data/state management
I would disagree with that. As soon as you need to get data in an asynchronous way, RxJS will be a good tool to use.
For example, let's say you want to display the user with the ID passed as input to a component, the easiest way to do that in a clean way would be to do something like

  userId = input.required<string>();
  user: Signal<User | undefined> = toSignal(toObservable(this.userId).pipe(switchMap(id => userService.get(id)));
swift axle
#

Doesn't this look already too complicated to you?
user: Signal<User | undefined> = toSignal(toObservable(this.userId).pipe(switchMap(id => userService.get(id)));

I mean the main selling point of Signals seems to be that state management code would be less complex and easier to read than RxJS. Maybe I am missing something here

autumn stag
swift axle
#

Why should I use Signals then? Just to ditch the async pipe ?

quasi smelt
quasi smelt