2018-12-17 17:34:32 +01:00
|
|
|
import { actionTypes } from './actions'
|
2020-06-05 16:59:13 +02:00
|
|
|
import { HYDRATE } from 'next-redux-wrapper'
|
2017-07-13 20:55:29 +02:00
|
|
|
|
2020-06-05 16:59:13 +02:00
|
|
|
const initialState = {
|
2017-07-13 20:55:29 +02:00
|
|
|
count: 0,
|
|
|
|
error: false,
|
|
|
|
lastUpdate: 0,
|
|
|
|
light: false,
|
2019-11-11 04:24:53 +01:00
|
|
|
placeholderData: null,
|
2017-07-13 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
2022-03-18 11:20:20 +01:00
|
|
|
function reducer(state = initialState, action) {
|
2017-07-13 20:55:29 +02:00
|
|
|
switch (action.type) {
|
2020-06-05 16:59:13 +02:00
|
|
|
case HYDRATE: {
|
2020-05-25 18:21:35 +02:00
|
|
|
return { ...state, ...action.payload }
|
|
|
|
}
|
|
|
|
|
2017-07-13 20:55:29 +02:00
|
|
|
case actionTypes.FAILURE:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-11-11 04:24:53 +01:00
|
|
|
...{ error: action.error },
|
2017-07-13 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.INCREMENT:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-11-11 04:24:53 +01:00
|
|
|
...{ count: state.count + 1 },
|
2017-07-13 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
2018-05-16 10:47:12 +02:00
|
|
|
case actionTypes.DECREMENT:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-11-11 04:24:53 +01:00
|
|
|
...{ count: state.count - 1 },
|
2018-05-16 10:47:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.RESET:
|
|
|
|
return {
|
|
|
|
...state,
|
2020-06-05 16:59:13 +02:00
|
|
|
...{ count: initialState.count },
|
2018-05-16 10:47:12 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 20:55:29 +02:00
|
|
|
case actionTypes.LOAD_DATA_SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-11-11 04:24:53 +01:00
|
|
|
...{ placeholderData: action.data },
|
2017-07-13 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
case actionTypes.TICK_CLOCK:
|
|
|
|
return {
|
|
|
|
...state,
|
2019-11-11 04:24:53 +01:00
|
|
|
...{ lastUpdate: action.ts, light: !!action.light },
|
2017-07-13 20:55:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default reducer
|