Last active
October 7, 2017 20:25
-
-
Save vzaidman/784ef340d0db6a22c21d3fd1b56defee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { checkError } from './actions' | |
export const checkErrorReducer = makeAsyncReducer(checkError, { | |
shouldSpread: true, | |
destroyData: false | |
}) | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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