Created
November 29, 2018 17:23
-
-
Save tuandinh0801/ac8744ea5a1e458ce8d3339e523a9c56 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
const handleDrawingEvent = line => ({ | |
line, | |
type: 'LINE_DRAWN' | |
}) | |
const drawingSyncSuccess = () => ({ | |
type: 'DRAWING_SYNC_SUCCESS', | |
}) | |
const drawingSyncFailure = () => ({ | |
type: 'DRAWING_SYNC_FAILED', | |
}) | |
const drawingSyncFailure = () => ({ | |
type: 'DRAWING_MOUSE_UP', | |
}) | |
function loadDataEpic(action$) { | |
return action$ | |
.ofType('LINE_DRAWN') | |
.bufferBy(action$.ofType('DRAWING_MOUSE_UP')) | |
.switchMap((lines) => | |
fetch('/a/fake/url', { | |
method: 'post', | |
body: JSON.stringify(lines) | |
}) | |
.then(response => response.ok ? drawingSyncSuccess() : drawingSyncFailure()) | |
.catch(() => drawingSyncFailure()) | |
) | |
} | |
const reducer = (state = {}, action) => { | |
switch (action.type) { | |
case 'DRAWING_SYNC_SUCCESS': | |
return { ...state, drawingSyncSuccess: true, drawingSyncFailed: false } | |
case 'DRAWING_SYNC_FAILED': | |
return { ...state, drawingSyncFailed: true, drawingSyncSuccess: false } | |
default: | |
return state; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment