Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs improvements #140

Closed
wants to merge 42 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
ad49ffa
Add terminology.md
acdlite Jun 18, 2015
22f377b
Start FAQ document
emmenko Jun 18, 2015
6c5f055
Merge branch 'master' into improve-docs
emmenko Jun 29, 2015
d96f5f4
Add some JSDoc
emmenko Jun 29, 2015
af89752
More JSDoc
emmenko Jun 29, 2015
da2fa45
More JSDoc
emmenko Jun 29, 2015
39a8107
Still more JSDoc
emmenko Jun 29, 2015
0c16baa
Merge pull request #214 from gaearon/gaearon-patch-1
gaearon Jul 5, 2015
b15f0e6
Add terminology.md
acdlite Jun 18, 2015
41f0bdf
Start FAQ document
emmenko Jun 18, 2015
d816847
Add some JSDoc
emmenko Jun 29, 2015
b8308ec
More JSDoc
emmenko Jun 29, 2015
9de7b44
More JSDoc
emmenko Jun 29, 2015
bbca371
Still more JSDoc
emmenko Jun 29, 2015
35b8da5
Merge branch 'improve-docs' of https://github.com/gaearon/redux into …
acdlite Jul 5, 2015
5efcc08
Add higher-order store docs
acdlite Jul 5, 2015
c7e37e4
Split README into separate docs
acdlite Jul 9, 2015
01b8e41
FAQ
acdlite Jul 9, 2015
9522aed
Add types and terminology
acdlite Jul 9, 2015
1f19428
Remove extraneous file
acdlite Jul 9, 2015
9de7445
Typos and clarficiation
acdlite Jul 9, 2015
7e5a829
Fix higher-order store type signature
acdlite Jul 9, 2015
5433e2c
Fix Flow types
acdlite Jul 10, 2015
d64f1b4
Update store.md
ellbee Jul 12, 2015
4b8418f
Merge pull request #255 from ellbee/stores-doc
acdlite Jul 12, 2015
50c496c
Merge branch 'improve-docs' of https://github.com/gaearon/redux into …
acdlite Jul 12, 2015
9dd724d
Getting Started guide
acdlite Jul 12, 2015
bfc8c26
Fix page title
acdlite Jul 12, 2015
126ac3e
Typo
acdlite Jul 12, 2015
3ade4b0
combine => combineReducers
acdlite Jul 12, 2015
6805327
Update store.md
ellbee Jul 13, 2015
f5a90cd
Update store.md
ellbee Jul 13, 2015
9050a5f
Reference react-redux within react.md
mcamac Jul 13, 2015
cdaa3e8
Merge pull request #260 from mcamac/improve-docs-react
gaearon Jul 13, 2015
8d78e49
Update store.md
ellbee Jul 13, 2015
1d207ba
Update store.md
ellbee Jul 13, 2015
2bb3769
Update store.md
ellbee Jul 14, 2015
2afae08
Merge pull request #258 from ellbee/stores-doc
gaearon Jul 14, 2015
a6f16ee
Remove extra 'a' in doc
chentsulin Jul 15, 2015
224aef7
Merge pull request #269 from chentsulin/patch-1
gaearon Jul 15, 2015
1452d8b
Fix a broken link in middleware.md
chentsulin Jul 17, 2015
82532a4
Merge pull request #280 from chentsulin/patch-2
gaearon Jul 17, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
453 changes: 0 additions & 453 deletions README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions docs/design-goals.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
### Philosophy & Design Goals

* You shouldn't need a book on functional programming to use Redux.
* Everything (Stores, Action Creators, configuration) is hot reloadable.
* Preserves the benefits of Flux, but adds other nice properties thanks to its functional nature.
* Prevents some of the anti-patterns common in Flux code.
* Works great in [universal (aka “isomorphic”)](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) apps because it doesn't use singletons and the data can be rehydrated.
* Doesn't care how you store your data: you may use JS objects, arrays, ImmutableJS, etc.
* Under the hood, it keeps all your data in a tree, but you don't need to think about it.
* Lets you efficiently subscribe to finer-grained updates than individual Stores.
* Provides hooks for powerful devtools (e.g. time travel, record/replay) to be implementable without user buy-in.
* Provides extension points so it's easy to [support promises](https://github.com/gaearon/redux/issues/99#issuecomment-112212639) or [generate constants](https://gist.github.com/skevy/8a4ffc3cfdaf5fd68739) outside the core.
* No wrapper calls in your stores and actions. Your stuff is your stuff.
* It's super easy to test things in isolation without mocks.
* You can use “flat” Stores, or [compose and reuse Stores](https://gist.github.com/gaearon/d77ca812015c0356654f) just like you compose Components.
* The API surface area is minimal.
* Have I mentioned hot reloading yet?
39 changes: 39 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
## Examples

### Simple Examples

Redux is distributed with a Counter and a TodoMVC example in its source code.

First, clone the repo:

```
git clone https://github.com/gaearon/redux.git
cd redux
```

Run the Counter example:

```
cd redux/examples/counter
npm install
npm start
```

Run the TodoMVC example:

```
cd ../todomvc
npm install
npm start
```

### Async and Universal Examples with Routing

These async and [universal (aka “isomorphic”)](https://medium.com/@mjackson/universal-javascript-4761051b7ae9) examples using React Router should help you get started:

* [redux-react-router-async-example](https://github.com/emmenko/redux-react-router-async-example): Work in progress. Semi-official. Only the client side. Uses React Router.
* [react-redux-universal-hot-example](https://github.com/erikras/react-redux-universal-hot-example): Universal. Uses React Router.
* [redux-example](https://github.com/quangbuule/redux-example): Universal. Uses Immutable, React Router.
* [isomorphic-counter-example](https://github.com/khtdr/redux-react-koa-isomorphic-counter-example): Universal. A bare-bone implentation of the [counter example app](https://github.com/gaearon/redux/tree/master/examples/counter). Uses promises-middleware to interact with API via Koa on the server.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

implentation -> implementation


Don’t be shy, add your own!
101 changes: 101 additions & 0 deletions docs/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
## FAQ

### How does hot reloading work?

* http://webpack.github.io/docs/hot-module-replacement.html
* http://gaearon.github.io/react-hot-loader/
* Literally that's it. Redux is fully driven by component props, so it works on top of React Hot Loader.

### Can I use this in production?

Yep. People already do that although I warned them! The API surface is minimal so migrating to 1.0 API when it comes out won't be difficult. Let us know about any issues.

### How do I do async?

There's already a built-in way of doing async action creators:

```js
// Can also be async if you return a function
export function incrementAsync() {
return dispatch => {
setTimeout(() => {
// Yay! Can invoke sync or async actions with `dispatch`
dispatch(increment());
}, 1000);
};
}
```

It's also easy to implement support for returning Promises or Observables with a custom middleware. [See an example of a custom Promise middleware.](https://github.com/gaearon/redux/issues/99#issuecomment-112212639)

### But there are switch statements!

`(state, action) => state` is as simple as a Store can get. You are free to implement your own `createStore`:

```js
export default function createStore(initialState, handlers) {
return (state = initialState, action) =>
handlers[action.type] ?
handlers[action.type](state, action) :
state;
}
```

and use it for your Stores:

```js
export default createStore(0, {
[INCREMENT_COUNTER]: x => x + 1,
[DECREMENT_COUNTER]: x => x - 1
});
```

It's all just functions.
Fancy stuff like generating stores from handler maps, or generating action creator constants, should be in userland.
Redux has no opinion on how you do this in your project.

See also [this gist](https://gist.github.com/skevy/8a4ffc3cfdaf5fd68739) for an example implementation of action constant generation.

### What about `waitFor`?

I wrote a lot of vanilla Flux code and my only use case for it was to avoid emitting a change before a related Store consumes the action. This doesn't matter in Redux because the change is only emitted after *all* Stores have consumed the action.

If several of your Stores want to read data from each other and depend on each other, it's a sign that they should've been a single Store instead. [See this discussion on how `waitFor` can be replaced by the composition of stateless Stores.](https://gist.github.com/gaearon/d77ca812015c0356654f)

### My views aren't updating!

Redux makes a hard assumption that you never mutate the state passed to you. It's easy! For example, instead of

```js
function (state, action) {
state.isAuthenticated = true;
state.email = action.email;
return state;
}
```

you should write

```js
function (state, action) {
return {
...state,
isAuthenticated: true,
email: action.email
};
}
```

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

### How do Stores, Actions and Components interact?

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.

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.

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.

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.

There is no other “interaction” in Redux.
Loading