Shopping in a Redux Store

2019/08/20
redux, store, state, pattern

Redux is set of very simple but also very useful ideas:

And when combined with a declarative UI like React, the result can be quite good.

what happened

Some history of our Redux&React journey:

When starting with React and Redux, most of us may spend a lot of time focusing on syntax, and the somewhat repetitive 'boilerplate'.

Then the initial confusing phase pass, the syntax works, the code piles up, the first rev of UI is done. But the UI tree feels wired and shaky:

Then it occurs to us: maybe it's time to finally fully complete the docs for Redux and React, seriously, and no skipping.

And from the doc, push the UI code down, lift the data and control code up the tree is a good idea, also clear up the lazy naming for some of the props & Component helps, too.

The second rev of UI survives more iteration, during which one or more redux middleware is introduced for async actions, store state gets more crowded, the code works, still somewhat readable, but still hard to discuss.

Then the ideas of modularize of UI and data code comes, most of the time, the UI is not one big problem, but several smaller separated module problem to solve. The code split up for each module, with code for both the UI and data.

So a better code structure is designed: some module each with a smaller store, and a smaller UI tree, then some wrapper code to compose these up.

what we ended up with is modular data & UI code:

and some opinionated extra simplification/modification:

basically we valued:

for the middleware, search for redux-entry

what worked

React&Redux worked for us because:

generalization, expanding the store pattern

The concept of store is not limited to React or frontend only

We can generalize UI to be some visible output, or just output, then a common data flow with store can be like:

action -> store & state -> output

we may apply the redux-like store code structure to some different scenario: