Skip to content

Instantly share code, notes, and snippets.

@aigoncharov
Last active February 11, 2019 19:02
Show Gist options
  • Save aigoncharov/20ef4be5a33130adaa99601f9bf4cb1c to your computer and use it in GitHub Desktop.
Save aigoncharov/20ef4be5a33130adaa99601f9bf4cb1c to your computer and use it in GitHub Desktop.
Reducer organization - taking a step further
import { createReducer } from 'redux-create-reducer'
const actionTypeJediCreateInit = 'jedi-app/jedi-create-init'
const actionTypeJediCreateSuccess = 'jedi-app/jedi-create-success'
const actionTypeJediCreateError = 'jedi-app/jedi-create-error'
const reducerJediInitialState = {
loading: false,
data: [],
error: undefined,
}
const reducerJedi = createReducer(reducerJediInitialState, {
[actionTypeJediCreateInit]: (state) => ({
...state,
loading: true,
}),
[actionTypeJediCreateSuccess]: (state, action) => ({
loading: false,
data: [...state.data, action.payload],
error: undefined,
}),
[actionTypeJediCreateError]: (state, action) => ({
...state,
loading: false,
error: action.payload,
}),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment