Last active
May 7, 2019 16:54
-
-
Save hendrikswan/d64fc2bc450e392d4bc872eb10318957 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
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
drawingSyncFailure
variable name has been used twice. I reckon second action creator name it should bedrawingMouseUp
.