Skip to content

Instantly share code, notes, and snippets.

@fxlrnrpt
Last active January 9, 2019 13:18
Show Gist options
  • Select an option

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

Select an option

Save fxlrnrpt/1cdc495fff27e8dc0359fd8f5048332e to your computer and use it in GitHub Desktop.
class ActionStandard {
get static type () {
return `prefix/${this.name}`
}
constructor(payload) {
this.type = this.constructor.type
this.payload = payload
this.error = payload instanceof Error
}
}
class CatsGetInit extends ActionStandard {}
class CatsGetSuccess extends ActionStandard {}
class CatsGetError extends ActionStandard {}
const reducerCatsInitialState = {
error: undefined,
data: undefined,
loading: false,
}
const reducerCats = (state = reducerCatsInitialState, action) => {
switch (action.type) {
case CatsGetInit.type:
return {
...state,
loading: true,
}
case CatsGetSuccess.type:
return {
error: undefined,
data: action.payload,
loading: false,
}
case CatsGetError.type:
return {
...data,
error: action.payload,
loading: false,
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment