Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hendrikswan/d64fc2bc450e392d4bc872eb10318957 to your computer and use it in GitHub Desktop.
Save hendrikswan/d64fc2bc450e392d4bc872eb10318957 to your computer and use it in GitHub Desktop.
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;
}
}
@dmnrmr
Copy link

dmnrmr commented Jan 16, 2018

drawingSyncFailure variable name has been used twice. I reckon second action creator name it should be drawingMouseUp.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment