-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.js
77 lines (72 loc) · 1.72 KB
/
.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import { combineReducers } from 'redux';
import {
SELECT_REDDIT , INVALIDATE_REDDIT ,
REQUEST_POSTS , RECEIVE_POSTS ,
} from '../actions';
const selectedReddit = (
state = 'reactjs' ,
action ,
) => {
switch ( action.type ) {
case SELECT_REDDIT:
return action.reddit;
default:
return state;
}
};
const posts = (
state = {
isFetching : false ,
didInvalidate : false ,
items : [] ,
} ,
action ,
) => {
switch ( action.type ) {
case INVALIDATE_REDDIT:
return {
...state ,
didInvalidate : true ,
};
case REQUEST_POSTS:
return {
...state ,
isFetching : true ,
didInvalidate : false ,
};
case RECEIVE_POSTS:
return {
...state ,
isFetching : false ,
didInvalidate : false ,
items : action.posts ,
lastUpdated : action.receivedAt ,
};
default:
return state;
}
};
const postsByReddit = (
state = {} ,
action ,
) => {
switch ( action.type ) {
case INVALIDATE_REDDIT:
case RECEIVE_POSTS:
case REQUEST_POSTS:
return {
...state ,
[action.reddit] : posts(
state[action.reddit] ,
action ,
) ,
};
default:
return state;
}
};
const rootReducer = combineReducers(({
postsByReddit ,
selectedReddit ,
}));
export default rootReducer;