What's the crucial difference between Angular 2 Data Flow and Flux?
Asked Answered
P

2

8

Hi I am studying Angular 2 and React + Redux right now, and I have a question on the difference of the difference in data flow of those two choices.

  1. Angular 2 uses uni-directional data flow by default. Redux is a Flux implementation, which (also) uses uni-directional data flow. What is the crucial difference among those? (is it maybe, the composition of parts?)
  2. If those two are not so much different in terms of how data flows, why would anyone use Flux or Redux over default choice of Angular 2 framework?
  3. If those two are quite different, is there a name I can call for Angular 2's data flow for further references to compare those two?

Thanks a lot in advance !

Pilch answered 13/3, 2017 at 14:26 Comment(0)
D
7

If those two are not so much different in terms of how data flows, why would anyone use Flux or Redux over default choice of Angular 2 framework?

Angular mostly provides UI layer (components) while the state management is not predefined by the framework. Since angular has services, you can keep the business logic in services (stateful services) and UI state in components (stateful components), but it means that there is no single place for the state as it is distributed among services/components.

The main reason to use redux in angular application is to separate UI layer from the data layer. In redux, the state is separated into a separate layer (think single tree-like object) which gets synchronized with UI layer (components) through special services injected into components constructor (check this setup).

If those two are quite different, is there a name I can call for Angular 2's data flow for further references to compare those two?

I haven't come across one, probably because as I mentioned above angular as a framework is focused on presentation, not state.

Dray answered 13/3, 2017 at 14:52 Comment(2)
Thanks for the answer! One additional question. As far as I know, Flux (as FB's flux implementation) does not force to use one store for all states as Redux does. So is Flux generally similar as having business logics in services of Angular?Pilch
@sangyongjung, I don't have much experience with Flux, but I would think that yes, in some way they are similar.Dray
H
3

By using Redux with angular 2, you are centralizing your application state in a single place totally seperate from your components: the store.

Your components can then be stateless, allowing you to disable internal change detection on them like this.

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush
})
class myComponent {
  @Input() inputFromTheStore: Observable<State>;
}

Indeed the above example is a stateless component, on wich you plug in a stream of state.

Also to answer your question :

Angular 2 uses uni-directional data flow by default. Redux is a Flux implementation, which (also) uses uni-directional data flow. What is the crucial difference among those? (is it maybe, the composition of parts?)

The crucial difference is that with Redux the state will always be coming in from above via @Input(). Unlike traditional angular2 statefull components where state could transit through @Input() and @Output().

Heptad answered 13/3, 2017 at 15:26 Comment(1)
Thank you ver much!Pilch

© 2022 - 2024 — McMap. All rights reserved.