Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rxjs/ngrx multicast on .select

In a @Component, should I always multicast the .select(myCustomSelector)?

e.g.

this.store.select(myCustomSelector).pipe(share());

Otherwise every time I do async, it will create a new subscription. Or is it fine because the selector is memoized?

I am wondering what's good practice.

like image 973
Dolan Avatar asked Jul 17 '26 05:07

Dolan


1 Answers

No you should not use share() with your .select()

But it depends on what store implementation you are using.

in ngrx, ngxs, akita, the store is backed by an object and thus the observable returned from the select isn't going to trigger any side effects.

the store is then updated via a reducer, and then all the selects will get a new value, but since they are all working of this single object (state), it will not be a performance problem.

like image 70
Leon Radley Avatar answered Jul 18 '26 22:07

Leon Radley



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!