Skip to content

Instantly share code, notes, and snippets.

@vzaidman
Last active October 7, 2017 20:25
Show Gist options
  • Save vzaidman/784ef340d0db6a22c21d3fd1b56defee to your computer and use it in GitHub Desktop.
Save vzaidman/784ef340d0db6a22c21d3fd1b56defee to your computer and use it in GitHub Desktop.
import { checkError } from './actions'
export const checkErrorReducer = makeAsyncReducer(checkError, {
shouldSpread: true,
destroyData: false
})
import { checkError } from './actions'
import { checkErrorReducer } from './errorReducer'
const state1 = asyncReducer(undefined, {type: '@@INIT'})
// state1 ⇒ {
// loading: false
// }
const state2 = asyncReducer(state1, checkError())
// state2 ⇒ {
// loading: true
// }
const state3 = asyncReducer(state2, checkError.success({ code: 404, message: 'NOT FOUND' }))
// state3 ⇒ {
// loading: false,
// code: 404,
// message: 'NOT FOUND'
// }
// as opposed to the previous example,
// here, data is not deleted on re-launching the process
// because "destroyData" is set to false
const state4 = asyncReducer(state3, checkError())
// state4 ⇒ {
// loading: true,
// code: 404,
// message: 'NOT FOUND'
// }
const state5 = asyncReducer(state4, checkError.error('Fetch Error'))
// state5 ⇒ {
// loading: false,
// error: 'Fetch Error'
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment