-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathreducers.js
41 lines (34 loc) · 939 Bytes
/
reducers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// Reducer is a pure function which have previous state and action then return next state
// (previousState, action) => newState
// Do not do that: change params in fn, any side-effects, use route system
// Initial State
const initialState = {
todos: []
};
// Reducer
function todoApp(state = initialState, action) {
switch (action.type) {
case 'ADD_TODO':
return Object.assign({}, state, {
text: action.text
});
case 'UPDATE_TODO':
return Object.assign({}, state, {
todos: [
...state.todos,
{
text: action.text
}
]
});
default:
return state;
}
}
// combineReducers
import {combineReducers} from 'redux';
const todoApp = combineReducers({
firstReducer,
secondReducers
});
export default todoApp;