2018-12-17 16:34:32 +00:00
|
|
|
import { actionTypes } from './actions'
|
2017-07-13 18:55:29 +00:00
|
|
|
|
|
|
|
export const exampleInitialState = {
|
|
|
|
count: 0,
|
|
|
|
error: false,
|
|
|
|
lastUpdate: 0,
|
|
|
|
light: false,
|
|
|
|
placeholderData: null
|
|
|
|
}
|
|
|
|
|
|
|
|
function reducer (state = exampleInitialState, action) {
|
|
|
|
switch (action.type) {
|
|
|
|
case actionTypes.FAILURE:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ error: action.error }
|
2017-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.INCREMENT:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ count: state.count + 1 }
|
2017-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
2018-05-16 08:47:12 +00:00
|
|
|
case actionTypes.DECREMENT:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ count: state.count - 1 }
|
2018-05-16 08:47:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.RESET:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ count: exampleInitialState.count }
|
2018-05-16 08:47:12 +00:00
|
|
|
}
|
|
|
|
|
2017-07-13 18:55:29 +00:00
|
|
|
case actionTypes.LOAD_DATA_SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ placeholderData: action.data }
|
2017-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.TICK_CLOCK:
|
|
|
|
return {
|
|
|
|
...state,
|
2018-12-17 16:34:32 +00:00
|
|
|
...{ lastUpdate: action.ts, light: !!action.light }
|
2017-07-13 18:55:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reducer
|