We are all talking about React these days, while a large number of React developers has been addicted to one the most popular Flux implementation — Redux.
Here is the official definition of Flux from Facebook:
Flux is the application architecture that Facebook uses for building client-side web applications. It complements React’s composable view components by utilizing a unidirectional data flow. It’s more of a pattern rather than a formal framework, and you can start using Flux immediately without a lot of new code.
Recently a friend of mine asked me a question: ‘I know React is kind of a way to write web views as components, but what the hell is Redux’?
Here is the story.
After graduating from college, you rent a small apartment in the downtown while working as a front-end developer in a small startup. Here is the map view of your living room.
One Saturday you invite your friend David to your apartment. David finds that the position of your furniture in the living room is kind of wired. Here every single furniture is a React component, and a number of components is what your living room looks like.
David and you ordered a pizza delivery and you plan to eat together at home with a recent popular movie. However, you both find it seems hard to sit, eat and watch TV at the same time, which is caused by the interaction with the furniture.
So here comes your plan, you want to rearrange your furniture like this:
You ask David to move the TV first, then the table.
All done. Now pizza and movie time!
End.
First let think about the dummy story again.
Then let’s take a look for the core concepts of Redux (including React here).
So from a Redux perspective, the whole story should be:
view — -> action — -> reducer — -> store(state) — -> view
That exactly what this tricky Flux diagram means:
image from https://facebook.github.io/flux/docs/overview.html#content
Here is the code for the whole story.
And you can see the online demo here.
If you want to know about the settings for react and redux project with webpack and hot loading, please see here.
You can also find me here: