Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save fxlrnrpt/ea6916d17f771ed2d8035825eb3c1739 to your computer and use it in GitHub Desktop.
class ActionStandard {
get static type () {
return `prefix/${this.name}`
}
constructor(payload) {
return {
type: this.constructor.type,
payload,
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