-
Notifications
You must be signed in to change notification settings - Fork 0
/
store.js
49 lines (46 loc) · 1.03 KB
/
store.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
40
41
42
43
44
45
46
47
48
49
import { createStore, combineReducers, applyMiddleware } from 'redux'
import thunk from 'redux-thunk'
import { not, append, reject, propEq, merge } from 'ramda'
export default createStore(
combineReducers({
todos,
todo
}),
applyMiddleware(thunk)
)
function todos(state = [], action) {
switch (action.type) {
case 'SET_TODOS':
return action.payload
case 'REMOVE_TODO':
return reject(propEq('_id', action.payload._id), state)
case 'UPSERT_TODO':
return append(
action.payload,
reject(propEq('_id', action.payload._id), state)
)
default:
return state
}
}
function todo(
state = {
description: '',
completed: false
},
action
) {
switch (action.type) {
case 'CHG_DESCRIPTION':
return merge(state, { description: action.payload })
case 'CLEAR_TODO':
return {
description: '',
completed: false
}
case 'TOGGLE_DONE':
return merge(state, { completed: not(state.completed) })
default:
return state
}
}