forked from editdata/submit-data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodify-state.js
More file actions
51 lines (49 loc) · 1.32 KB
/
modify-state.js
File metadata and controls
51 lines (49 loc) · 1.32 KB
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
var extend = require('xtend')
var modifiers = {
'loading': function (action, state) {
return extend(state, { loading: true })
},
'loading:complete': function (action, state) {
return extend(state, { loading: false })
},
'user:login': function (action, state) {
return extend(state, {
user: {
profile: action.profile,
token: action.token
}
})
},
'user:logout': function (action, state) {
return extend(state, { user: null })
},
'form:submit': function (action, state) {
var item = action.fields
var data = state.data
data.push(item)
return extend(state, {
item: item,
data: data
})
},
'submitted': function (action, state) {
return extend(state, {
submitted: true,
fork: action.fork,
branch: action.branch,
pullRequest: action.pullRequest
})
},
'error': function (action, state) {
return extend(state, { error: action.error })
}
}
module.exports = function modifier (action, state) {
console.log('-------------------------------------')
console.log('action:', action.type, action)
var newState = modifiers[action.type](action, state)
console.log('.....................................')
console.log('new state:', newState)
//console.log('-------------------------------------')
return newState
}