[Enhancement] Apply immutable js. (#49)

This commit is contained in:
Qolzam
2018-04-04 10:33:15 +07:00
parent b94d2a0124
commit 9cd2672395
98 changed files with 1294 additions and 1633 deletions

View File

@@ -3,112 +3,86 @@ import { GlobalActionType } from 'constants/globalActionType'
import { GlobalState } from './GlobalState'
import { IGlobalAction } from './IGlobalAction'
import { Map, fromJS } from 'immutable'
/**
* Global reducer
* @param {object} state
* @param {object} action
*/
export const globalReducer = (state: GlobalState = new GlobalState(), action: IGlobalAction) => {
export const globalReducer = (state = Map(new GlobalState()), action: IGlobalAction) => {
const { payload } = action
switch (action.type) {
case GlobalActionType.PROGRESS_CHANGE:
return {
...state,
progress: {
...state.progress,
percent: payload.percent,
visible: payload.visible
}
}
return state
.setIn(['progress', 'percent'], payload.percent)
.setIn(['progress', 'visible'], payload.visible)
case GlobalActionType.DEFAULT_DATA_DISABLE:
return {
...state,
defaultLoadDataStatus: false
}
return state
.set('defaultLoadDataStatus', false)
case GlobalActionType.DEFAULT_DATA_ENABLE:
return {
...state,
defaultLoadDataStatus: true
}
return state
.set('defaultLoadDataStatus', true)
case GlobalActionType.SHOW_MESSAGE_GLOBAL:
return {
...state,
message: action.payload,
messageOpen: true
}
return state
.set('message', action.payload)
.set('messageOpen', true)
case GlobalActionType.SHOW_NORMAL_MESSAGE_GLOBAL:
return {
...state,
message: action.payload,
messageOpen: true
}
return state
.set('message', action.payload)
.set('messageOpen', true)
case GlobalActionType.HIDE_MESSAGE_GLOBAL:
return {
...state,
message: '',
messageOpen: false,
messageColor: ''
}
return state
.set('message', action.payload)
.set('messageOpen', false)
.set('messageColor', '')
case GlobalActionType.SET_HEADER_TITLE:
return {
...state,
headerTitle: action.payload
}
return state
.set('headerTitle', action.payload)
case GlobalActionType.SHOW_SEND_FEEDBACK:
return {
...state,
sendFeedbackStatus: true
}
return state
.set('sendFeedbackStatus', true)
case GlobalActionType.HIDE_SEND_FEEDBACK:
return {
...state,
sendFeedbackStatus: false
}
return state
.set('sendFeedbackStatus', false)
case GlobalActionType.HIDE_TOP_LOADING:
const queueTopLoading = state.topLoadingQueue > 0 ? (state.topLoadingQueue - 1) : 0
return {
...state,
topLoadingQueue: queueTopLoading,
showTopLoading: (queueTopLoading > 0 ? true : false)
const queueTopLoading = Number(state.get('topLoadingQueue')) > 0 ? (Number(state.get('topLoadingQueue')) - 1) : 0
return state
.set('topLoadingQueue', queueTopLoading)
.set('showTopLoading', (queueTopLoading > 0 ? true : false))
}
case GlobalActionType.SHOW_TOP_LOADING:
return {
...state,
topLoadingQueue: (state.topLoadingQueue + 1),
showTopLoading: true
}
case GlobalActionType.HIDE_MASTER_LOADING:
const queueMasterLoading = state.masterLoadingQueue > 0 ? (state.masterLoadingQueue - 1) : 0
return {
...state,
masterLoadingQueue: queueMasterLoading,
showMasterLoading: (queueMasterLoading > 0 ? true : false)
return state
.set('topLoadingQueue', (Number(state.get('topLoadingQueue')) + 1))
.set('showTopLoading', true)
case GlobalActionType.HIDE_MASTER_LOADING:
const queueMasterLoading = Number(state.get('masterLoadingQueue')) > 0 ? (Number(state.get('masterLoadingQueue')) - 1) : 0
return state
.set('masterLoadingQueue', queueMasterLoading)
.set('showMasterLoading', (queueMasterLoading > 0 ? true : false))
}
case GlobalActionType.SHOW_MASTER_LOADING:
return {
...state,
masterLoadingQueue: (state.masterLoadingQueue + 1),
showMasterLoading: true
}
return state
.set('masterLoadingQueue', Number(state.get('masterLoadingQueue')) + 1)
.set('showMasterLoading', true)
case GlobalActionType.TEMP:
return {
...state,
temp: {
...state.temp,
caller: [
...state.temp.caller,
payload.caller
]
}
}
case GlobalActionType.CLEAR_ALL_GLOBAL:
return {
...state,
sendFeedbackStatus: false,
}
return state
.mergeIn(['temp', 'caller'], fromJS([payload.caller]))
case GlobalActionType.CLEAR_ALL_GLOBAL:
return state
.set('sendFeedbackStatus', false)
default:
return state