2018-02-04 11:56:32 +00:00
|
|
|
import * as types from './actionTypes'
|
|
|
|
|
|
|
|
const INITIAL_STATE = {
|
|
|
|
nextCharacterId: 1,
|
|
|
|
character: {},
|
|
|
|
isFetchedOnServer: false,
|
|
|
|
error: null
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function reducer (state = INITIAL_STATE, { type, payload }) {
|
|
|
|
switch (type) {
|
|
|
|
case types.FETCH_CHARACTER_SUCCESS:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
character: payload.response,
|
|
|
|
isFetchedOnServer: payload.isServer,
|
|
|
|
nextCharacterId: state.nextCharacterId + 1
|
|
|
|
}
|
|
|
|
case types.FETCH_CHARACTER_FAILURE:
|
2018-12-17 16:34:32 +00:00
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
error: payload.error,
|
|
|
|
isFetchedOnServer: payload.isServer
|
|
|
|
}
|
2018-02-04 11:56:32 +00:00
|
|
|
default:
|
|
|
|
return state
|
|
|
|
}
|
|
|
|
}
|