[web] Remove js/ducks/ui/option.js

This commit is contained in:
Matthew Shao 2017-07-20 22:26:28 +08:00
parent f465f08c9a
commit cb73658dd4
2 changed files with 0 additions and 78 deletions

View File

@ -1,39 +0,0 @@
import reduceOption, * as optionActions from '../../../ducks/ui/option'
describe('option reducer', () => {
it('should return the initial state', () => {
expect(reduceOption(undefined, {})).toEqual({})
})
let state = undefined
it('should handle option update start', () => {
state = reduceOption(undefined, {
type: optionActions.OPTION_UPDATE_START, option: 'foo', value: 'bar'
})
expect(state).toEqual({
foo: {
error: false,
isUpdating: true,
value: 'bar'
}
})
})
it('should handle option update success', () => {
expect(reduceOption(state, {
type: optionActions.OPTION_UPDATE_SUCCESS, option: 'foo'
})).toEqual({})
})
it('should handle option update error', () => {
expect(reduceOption(undefined, {
type: optionActions.OPTION_UPDATE_ERROR, option: 'foo', error: 'errorMsg'
})).toEqual({
foo: {
error: 'errorMsg',
isUpdating: false,
}
})
})
})

View File

@ -1,39 +0,0 @@
export const OPTION_UPDATE_START = 'UI_OPTION_UPDATE_START'
export const OPTION_UPDATE_SUCCESS = 'UI_OPTION_UPDATE_SUCCESS'
export const OPTION_UPDATE_ERROR = 'UI_OPTION_UPDATE_ERROR'
const defaultState = {
/* optionName -> {isUpdating, value (client-side), error} */
}
export default function reducer(state = defaultState, action) {
switch (action.type) {
case OPTION_UPDATE_START:
return {
...state,
[action.option]: {
isUpdating: true,
value: action.value,
error: false,
}
}
case OPTION_UPDATE_SUCCESS:
let s = {...state}
delete s[action.option]
return s
case OPTION_UPDATE_ERROR:
return {
...state,
[action.option]: {
...state[action.option],
isUpdating: false,
error: action.error
}
}
default:
return state
}
}