2. A predictable
state container
for JavaScript
apps
● Behaves consistently
● Runs in different
environment
○ Client
○ Server
○ Native
● Easy to test
3. A predictable
state container
for JavaScript
apps
● Can be used with
○ React
○ Angular
○ Any other view library
● Developer friendly
○ Live code editing
○ Time travelling debugger
9. State
type State = any
{
"visibilityFilter": "SHOW_ALL",
"tweets": [
{
"id": 0,
"text": "Hello World!!!",
"category": "text",
"isFavorite": false
}, …
]
}
10. Action
type Action = Object
{
"type": "ADD_TWEET",
"text": "Hello World!!!"
"category": "text"
}
Actions must have a type property that indicates
the type of action
11. Reducer
type Reducer = Function
(oldState, action) => newState
function addTweet(state = [], action) {
var tweets = state.slice();
tweets.push({
"id": state.length,
"text": action.text,
"category": action.category
"isFavorite": false
});
return tweets;
}
Do not put API calls into reducers
12. 3 Principles
of Redux
1. Single source of truth
2. State is read-only
3. Changes are made with pure
function (reducers)