Skip to content

Commit 9e007fd

Browse files
authored
Merge pull request #17 from Coding/yangzhen/FSAify-actions
FSA-ify Git and Notification
2 parents 043c5fc + 0dd5ae2 commit 9e007fd

File tree

4 files changed

+44
-49
lines changed

4 files changed

+44
-49
lines changed

app/components/Git/actions.js

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ import { notify, NOTIFY_TYPE } from '../Notification/actions'
44
import { showModal, dismissModal } from '../Modal/actions'
55

66
export const GIT_STATUS = 'GIT_STATUS'
7-
export function updateStatus ({files, isClean}) {
7+
export function updateStatus (payload) {
88
return {
99
type: GIT_STATUS,
10-
files,
11-
isClean
10+
payload
1211
}
1312
}
1413

1514
export const GIT_UPDATE_COMMIT_MESSAGE = 'GIT_UPDATE_COMMIT_MESSAGE'
16-
export function updateCommitMessage (commitMessage) {
15+
export function updateCommitMessage (payload) {
1716
return {
1817
type: GIT_UPDATE_COMMIT_MESSAGE,
19-
commitMessage
18+
payload
2019
}
2120
}
2221

@@ -28,18 +27,18 @@ export function commit ({files, commitMessage: message}) {
2827
}
2928

3029
export const GIT_STAGE_FILE = 'GIT_STAGE_FILE'
31-
export function stageFile (file) {
30+
export function stageFile (payload) {
3231
return {
3332
type: GIT_STAGE_FILE,
34-
fileName: file.name
33+
payload
3534
}
3635
}
3736

3837
export const GIT_UNSTAGE_FILE = 'GIT_UNSTAGE_FILE'
39-
export function unstageFile (file) {
38+
export function unstageFile (payload) {
4039
return {
4140
type: GIT_UNSTAGE_FILE,
42-
fileName: file.name
41+
payload
4342
}
4443
}
4544

@@ -57,7 +56,7 @@ export function getBranches () {
5756
api.gitBranch().then(data => {
5857
dispatch({
5958
type: GIT_BRANCH,
60-
branches: data
59+
payload: { branches: data }
6160
})
6261
})
6362
}
@@ -99,15 +98,15 @@ export const GIT_CURRENT_BRANCH = 'GIT_CURRENT_BRANCH'
9998
export function updateCurrentBranch ({ name }) {
10099
return {
101100
type: GIT_CURRENT_BRANCH,
102-
branch: name,
101+
payload: {branch: name},
103102
}
104103
}
105104

106105
export const GIT_UPDATE_STASH_MESSAGE = 'GIT_UPDATE_STASH_MESSAGE'
107-
export function updateStashMessage (stashMessage) {
106+
export function updateStashMessage (payload) {
108107
return {
109108
type: GIT_UPDATE_STASH_MESSAGE,
110-
stashMessage,
109+
payload,
111110
}
112111
}
113112

@@ -127,34 +126,34 @@ export function createStash (message) {
127126
}
128127

129128
export const GIT_UPDATE_STASH_LIST = 'GIT_UPDATE_STASH_LIST'
130-
export function updateStashList (stashList) {
129+
export function updateStashList (payload) {
131130
return {
132131
type: GIT_UPDATE_STASH_LIST,
133-
stashList: stashList
132+
payload
134133
}
135134
}
136135

137136
export const GIT_UPDATE_UNSTASH_IS_POP = 'GIT_UPDATE_UNSTASH_IS_POP'
138-
export function updateUnstashIsPop (isPop) {
137+
export function updateUnstashIsPop (payload) {
139138
return {
140139
type: GIT_UPDATE_UNSTASH_IS_POP,
141-
isPop
140+
payload
142141
}
143142
}
144143

145144
export const GIT_UPDATE_UNSTASH_IS_REINSTATE = 'GIT_UPDATE_UNSTASH_IS_REINSTATE'
146-
export function updateUnstashIsReinstate (isReinstate) {
145+
export function updateUnstashIsReinstate (payload) {
147146
return {
148147
type: GIT_UPDATE_UNSTASH_IS_REINSTATE,
149-
isReinstate
148+
payload
150149
}
151150
}
152151

153152
export const GIT_UPDATE_UNSTASH_BRANCH_NAME = 'GIT_UPDATE_UNSTASH_BRANCH_NAME'
154-
export function updateUnstashBranchName (newBranchName) {
153+
export function updateUnstashBranchName (payload) {
155154
return {
156155
type: GIT_UPDATE_UNSTASH_BRANCH_NAME,
157-
newBranchName
156+
payload
158157
}
159158
}
160159

@@ -165,10 +164,10 @@ export function getStashList () {
165164
}
166165

167166
export const GIT_SELECT_STASH = 'GIT_SELECT_STASH'
168-
export function selectStash (selectedStash) {
167+
export function selectStash (payload) {
169168
return {
170169
type: GIT_SELECT_STASH,
171-
selectedStash: selectedStash
170+
payload
172171
}
173172
}
174173

app/components/Git/reducer.js

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,68 +46,64 @@ export default function GitReducer (state = _state, action) {
4646
switch (action.type) {
4747

4848
case GIT_STATUS:
49-
var workingDirDelta = {
50-
isClean: action.isClean,
51-
files: action.files
52-
}
53-
state.workingDir = Object.assign({}, state.workingDir, workingDirDelta)
49+
state.workingDir = Object.assign({}, state.workingDir, action.payload)
5450
return state
5551

5652
case GIT_UPDATE_COMMIT_MESSAGE:
57-
state.stagingArea.commitMessage = action.commitMessage
53+
state.stagingArea.commitMessage = action.payload
5854
return state
5955

6056
case GIT_STAGE_FILE:
61-
state.stagingArea.files = _.union(state.stagingArea.files, [action.fileName])
57+
state.stagingArea.files = _.union(state.stagingArea.files, [action.payload.name])
6258
return state
6359

6460
case GIT_UNSTAGE_FILE:
65-
state.stagingArea.files = _.without(state.stagingArea.files, action.fileName)
61+
state.stagingArea.files = _.without(state.stagingArea.files, action.payload.name)
6662
return state
6763

6864
case GIT_BRANCH:
69-
state.branches = action.branches
65+
state.branches = action.payload.branches
7066
return state
7167

7268
case GIT_CHECKOUT:
7369
state.branches.current = action.branch
7470
return state
7571

7672
case GIT_CURRENT_BRANCH:
77-
state.branches.current = action.branch
73+
state.branches.current = action.payload.branch
7874
return state
7975

8076
case GIT_UPDATE_STASH_MESSAGE:
81-
state.stash.stashMessage = action.stashMessage
77+
state.stash.stashMessage = action.payload
8278
return state
8379

8480
case GIT_UPDATE_UNSTASH_IS_POP:
85-
state.unstash.isPop = action.isPop
81+
state.unstash.isPop = action.payload
8682
return state
8783

8884
case GIT_UPDATE_UNSTASH_IS_POP:
8985
state.unstash.isPop = action.isPop
9086
return state
9187

9288
case GIT_UPDATE_UNSTASH_IS_REINSTATE:
93-
state.unstash.isReinstate = action.isReinstate
89+
state.unstash.isReinstate = action.payload
9490
return state
9591

9692
case GIT_UPDATE_UNSTASH_BRANCH_NAME:
97-
state.unstash.newBranchName = action.newBranchName
93+
state.unstash.newBranchName = action.payload
9894
return state
9995

10096
case GIT_UPDATE_STASH_LIST:
101-
state.unstash.stashList = action.stashList
102-
if (action.stashList.length == 0) {
97+
state.unstash.stashList = action.payload
98+
if (state.unstash.stashList.length == 0) {
10399
state.unstash.selectedStash = null
104100
} else if(!state.unstash.selectedStash) {
105-
state.unstash.selectedStash = action.stashList[0]
101+
state.unstash.selectedStash = state.unstash.stashList[0]
106102
}
107103
return state
108104

109105
case GIT_SELECT_STASH:
110-
state.unstash.selectedStash = action.selectedStash
106+
state.unstash.selectedStash = action.payload
111107
return state
112108

113109
default:

app/components/Notification/actions.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* @flow weak */
22
export const NOTIFICATION_ADD = 'NOTIFICATION_ADD'
3-
export function addNotification (_notification) {
3+
export function addNotification (payload) {
44
return dispatch => {
55
var notification, defaultNotification
66

@@ -12,19 +12,19 @@ export function addNotification (_notification) {
1212
onClick: () => dispatch({type: NOTIFICATION_REMOVE, notification})
1313
}
1414

15-
let { notifyType } = _notification
15+
let { notifyType } = payload
1616
if (notifyType === NOTIFY_TYPE.ERROR) {
1717
defaultNotification = {...defaultNotification, ...{
1818
barStyle: { backgroundColor:'red' },
1919
actionStyle: { color:'white' }
2020
}}
2121
}
2222

23-
notification = {...defaultNotification, ..._notification}
23+
payload = {...defaultNotification, ...payload}
2424

2525
dispatch({
2626
type: NOTIFICATION_ADD,
27-
notification
27+
payload
2828
})
2929
}
3030
}
@@ -37,9 +37,9 @@ export const NOTIFY_TYPE = {
3737
}
3838

3939
export const NOTIFICATION_REMOVE = 'NOTIFICATION_REMOVE'
40-
export function removeNotification (notification) {
40+
export function removeNotification (payload) {
4141
return {
4242
type: NOTIFICATION_REMOVE,
43-
notification
43+
payload
4444
}
4545
}

app/components/Notification/reducer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ export default function NotificationReducer (state = {notifications: []}, action
1111

1212
switch (action.type) {
1313
case NOTIFICATION_ADD:
14-
state.notifications.push(action.notification)
14+
state.notifications.push(action.payload)
1515
return state
1616

1717
case NOTIFICATION_REMOVE:
18-
_.remove(state.notifications, action.notification)
18+
_.remove(state.notifications, action.payload)
1919
return state
2020

2121
default:

0 commit comments

Comments
 (0)