-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathupdater.js
93 lines (84 loc) · 1.88 KB
/
updater.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const { updateStateAt, combine, withDefaultState, decorate } = require('redux-fp')
const accessToken = action => (state = null) => {
switch (action.type) {
case 'SIGN_IN_SUCCESS':
return action.payload.accessToken
case 'LOG_OUT_SUCCESS':
return null
default:
return state
}
}
const credentialId = action => (state = null) => {
switch (action.type) {
case 'SIGN_IN_SUCCESS':
return action.payload.credentialId
case 'LOG_OUT_SUCCESS':
return null
default:
return state
}
}
const isSigningIn = action => (state = false) => {
switch (action.type) {
case 'SIGN_IN_START':
return true
case 'SIGN_IN_SUCCESS':
case 'SIGN_IN_ERROR':
return false
default:
return state
}
}
const isRegistering = action => (state = false) => {
switch (action.type) {
case 'REGISTER_START':
return true
case 'REGISTER_SUCCESS':
case 'REGISTER_ERROR':
return false
default:
return state
}
}
const signInError = action => (state = null) => {
switch (action.type) {
case 'SIGN_IN_START':
return null
case 'SIGN_IN_ERROR':
console.error(action.payload)
return action.payload
default:
return state
}
}
const registerError = action => (state = null) => {
switch (action.type) {
case 'REGISTER_START':
return null
case 'REGISTER_ERROR':
console.error(action.payload)
return action.payload
default:
return state
}
}
const localUpdater = decorate(
withDefaultState({}),
combine({
accessToken,
credentialId,
isSigningIn,
signInError,
isRegistering,
registerError
})
)
const globalDecorator = decorate(
withDefaultState({}),
updateStateAt('authentication'),
localUpdater
)
exports = module.exports = globalDecorator
exports.localUpdater = localUpdater
exports.globalDecorator = globalDecorator