Reputation: 175
I'm using Angular with container/presentation pattern and Ngxs. My problem is as follow:
I have one container component nested inside other container component and both call the same @Select
:
@Select(State.exaple) example$: Observable<boolean>;
I cannot pass example$
as an input and I cannot redesign the app.
My question is: should I use the @Select
twice or use a shared service?
If performance is the same or have minimum impact I will prefer using the double @Select
but I want to know if there is any problem with this approach or bad performance.
Upvotes: 0
Views: 136
Reputation: 6858
There will be minimal performance impact because all selectors are memoised (ie. the result is cached based on the inputs to the function. Given the same inputs to the function, the cached result will be returned and the function will not be run). There will be 2 subscriptions to the shared state ReplaySubject, but the impact of this is negligible.
Upvotes: 1