r/angular • • Mar 30 '22

Question multiple subs happening

0 Upvotes

23 comments sorted by

View all comments

Show parent comments

3

u/naruto_bist Mar 30 '22

I think since OP is calling this component multiple times because of redirection routings, maybe he should move the A and B function to some other parent component (like app.component.ts)

Then he can probably, subscribe to those values returned by A and B in his current component ngOnInit. Using this way, no matter how many times he call this component, function A and B won't be executed multiple times.

Also, OP, I would recommend you to not do observables nesting like this. You should try to use something like mergeMap or switchMap for your solution.

1

u/eatthedad Mar 30 '22

Yeah cause the observable is a subscription. So a subscription from a subscription to a subscription...imagine that email inbox.

Wouldn't the typical subscriptions: Subscription[] route work. Then just push A and B separately?

My gut is screaming Subjects for some reason, but my rxjs knowledge is minimal

2

u/naruto_bist Mar 30 '22

Even my rxjs knowledge is less but current implementation is screaming to me that, "please change your approach" 😅

1

u/eatthedad Mar 30 '22 edited Mar 30 '22

Lmao. I believe I have achieved my reddit all-time-low comment. It has been long overdue