I'm building an Angular 2 ngrx/store application and trying to understand best practices.
But I don't understand why we would want to "bubble up" events from dumb components all the way up to smart components before dispatching an action to the store. Is the only reason to have re-usable components? It seems to me that most components aren't re-used anyways cause there aren't many situations when I would want to have everything identical including the CSS. Are there any other benefits I'm missing? From the point of view of maintainability / readability, isn't it nicer to be able to just see the action dispatched right at the component where the interaction is happening?
First, I'm not an expert on the subject disclaimer.
store
, thus enhancing louse coupling. actions
allows for a quick overview of the architecture. Also hot-swapping of the store
access logic could be done easier.inputs
and outputs
. Ex: A dropdownComponent
could have a lot of usecases that require different inputs and outputs.I totally agree with you and I have the same doubt.
I expect the component to emit an action using the dispatcher (which for ngrx/store
is the store itself) instead of moving this logic to the container (the actual application).
This way the component is decoupled from the container and the container doesn't need to know about actions: it will just listen to the state change and pass down the eventual data, if necessary.
On the other hand, the Introduction to ngrx/store is promoting the design with a smarter container, which knows a lot about the underlying components.
Frankly, I can't yet see a clear winner: I just think that dispatching actions from the component is simpler, cleaner, and closer to the Elm Architecture which was one of the Redux's inspirations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With