Skip to content

Commit d925a04

Browse files
committed
Add some thoughts from #134
1 parent fc5621a commit d925a04

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ Atomic Flux with hot reloading.
3333
- [But there are switch statements!](#but-there-are-switch-statements)
3434
- [What about `waitFor`?](#what-about-waitfor)
3535
- [My views aren't updating!](#my-views-arent-updating)
36+
- [How do Stores, Actions and Components interact?](#how-do-stores-actions-and-components-interact)
3637
- [Discussion](#discussion)
3738
- [Inspiration and Thanks](#inspiration-and-thanks)
3839

@@ -419,6 +420,18 @@ function (state, action) {
419420

420421
[Read more](https://github.com/sebmarkbage/ecmascript-rest-spread) about the spread properties ES7 proposal.
421422

423+
### How do Stores, Actions and Components interact?
424+
425+
Action creators are just pure functions so they don't interact with anything. Components need to call `dispatch(action)` (or use `bindActionCreators` that wraps it) to dispatch an action *returned* by the action creator.
426+
427+
Stores are just pure functions too so they don't need to be “registered” in the traditional sense, and you can't subscribe to them directly. They're just descriptions of how data transforms. So in that sense they don't “interact” with anything either, they just exist, and are used by the dispatcher for computation of the next state.
428+
429+
Now, the dispatcher is more interesting. You pass all the Stores to it, and it composes them into a single Store function that it uses for computation. The dispatcher is also a pure function, and it is passed as configuration to `createRedux`, the only stateful thing in Redux. By default, the default dispatcher is used, so if you call `createRedux(stores)`, it is created implicitly.
430+
431+
To sum it up: there is a Redux instance at the root of your app. It binds everything together. It accepts a dispatcher (which itself accepts Stores), it holds the state, and it knows how to turn actions into state updates. Everything else (components, for example) subscribes to the Redux instance. If something wants to dispatch an action, they need to do it on the Redux instance. `Connector` is a handy shortcut for subscribing to a slice of the Redux instance's state and injecting `dispatch` into your components, but you don't have to use it.
432+
433+
There is no other “interaction” in Redux.
434+
422435
## Discussion
423436

424437
Join the **#redux** channel of the [Reactiflux](http://reactiflux.com/) Slack community

0 commit comments

Comments
 (0)