Skip to content

Instantly share code, notes, and snippets.

@fxlrnrpt
Created January 5, 2019 23:16
Show Gist options
  • Select an option

  • Save fxlrnrpt/a64ad39c55e3b393b0c692b178c1a744 to your computer and use it in GitHub Desktop.

Select an option

Save fxlrnrpt/a64ad39c55e3b393b0c692b178c1a744 to your computer and use it in GitHub Desktop.
const reducerLoading = (actionInit, actionSuccess, actionError) => (
state = false,
action,
) => {
switch (action.type) {
case actionInit.type:
return true
case actionSuccess.type:
return false
case actionError.type:
return false
}
}
class CatsGetInit extends ActionStandard {}
class CatsGetSuccess extends ActionStandard {}
class CatsGetError extends ActionStandard {}
const reducerCatsData = (state = undefined, action) => {
switch (action.type) {
case CatsGetSuccess.type:
return action.payload
default:
return state
}
}
const reducerCatsError = (state = undefined, action) => {
switch (action.type) {
case CatsGetError.type:
return action.payload
default:
return state
}
}
const reducerCats = combineReducers({
data: reducerCatsData,
loading: reducerLoading(CatsGetInit, CatsGetSuccess, CatsGetError),
error: reducerCatsError,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment