Redux vs services in Angular 2 Redux vs services in Angular 2 angular angular

Redux vs services in Angular 2


"Does migrating to Redux means all of this will be moved to store"

No.
If you are using ngrx then the best way to handle this would be with ngrx/effects. This is a companion library that is meant to be "the place to put your async code", or in other words the place to do side effects. So when the component wants some new data it would dispatch a "GET_DATA" action and this would be handled as an ngrx @Effect. Inside of your effect is where you can use your custom service to call out and retrieve the data (so your async services are probably fine and may just need to be tweaked a little). Then you effect returns an action containing the new data back to the reducer which updates the state with the new data. Your component was subscribing to store the whole time so when the state is updated by the reducer the component knows about this change and can automatically update it's own local state.


Thanks for your question. I am facing the same dilemma. The way I did answer myself for now is that I will still have testable services to encapsulate the state changing operations that the "redux" function executes.In my view, that redux function with a huge if statement that you see in basic redux examples is only a beginning... I guess nobody will code like that for real in a big app....I would say, however, that it looks like a good idea to have this redux intermediary that catches and dispatches any state-changing event to the corresponding service. Not sure still if we want also the read-only gets be encapsulated in the service... maybe not.. but that would be another discussion.