ncve
ncve

Reputation: 95

@ngrx/store and @ngrx/component-store communication

Is it ok for a ComponentStore to inject a global store to dispatch actions to the global store?

I have the following scenario:

So, knowing that the child component "A1" will need to trigger an action on child component "B". What's the best approach?

  1. "A1" injects the global store and dispatches an action. ParentComponent knows about the global store and passes the stream to child component "B".
  2. "A1" returns an Output that would be listened to by "A" which would then "bubble up" the same output by returning it to ParentComponent. ParentComponent knows about the global store and passes the stream to child component "B".

I would appreciate your input on this very much! Thanks!

Upvotes: 2

Views: 1334

Answers (1)

timdeschryver
timdeschryver

Reputation: 15505

It kinda depends (sorry).

If the global store is already used in your application, than option 1 would work. Especially if other parts of the application need to handle that event. On the other hand, you're just creating an event stream, which is similar to option 2, which is a manual event stream.

I would like to propose a third option, a component store that acts as a wrapper and interacts with component store A, and component store B.

Upvotes: 0

Related Questions