-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathreducer.es6
78 lines (69 loc) · 1.44 KB
/
reducer.es6
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
78
import { LOGIN, LOGOUT } from './auth/actions';
import { LOAD, SET_READY, SET_SETTINGS, SET_SYNCING } from './actions';
import authReducer, { DEFAULT as AUTH_DEFAULT } from './auth/reducer';
const DEFAULT = {
auth: AUTH_DEFAULT,
isLoading: false,
isReady: false,
isSyncing: false
};
export default function pouchReducer(state=DEFAULT, action) {
let nextState = state;
switch (action.type) {
case LOAD:
if (action.sequence.type === 'start') {
nextState = {
...state,
isLoading: true,
isReady: false
};
} else if (action.error) {
nextState = {
...state,
error: true,
isLoading: false,
isReady: false,
message: action.payload
};
} else {
nextState = {
...state,
auth: {
isLoading: false,
isReady: action.payload.isReady,
user: action.payload.user
},
isLoading: false,
isReady: true
};
}
break;
case LOGIN:
case LOGOUT:
nextState = {
...state,
auth: authReducer(state.auth, action)
};
break;
case SET_READY:
nextState = {
...state,
isReady: action.payload
};
break;
case SET_SETTINGS:
nextState = {
...state,
...action.payload
};
break;
case SET_SYNCING:
nextState = {
...state,
isSyncing: action.payload
};
break;
default: break;
}
return nextState;
}