Created
July 11, 2017 09:25
-
-
Save dzNavitski/30b147d2bad22f3cb208f1977777c08e 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 uploadDocumentEpic = action$ => | |
action$.ofType(UPLOAD_DOCUMENT).switchMap(action => { | |
const {id, data} = action.payload | |
const sub = new Subject() | |
const requester = Observable.fromPromise( | |
axios({ | |
url: 'https://api.foo.com', | |
data: { | |
file: data | |
}, | |
onUploadProgress: progressEvent => { | |
sub.next(progressEvent.loaded * 100 / progressEvent.total) | |
} | |
}) | |
) | |
return Observable.merge( | |
requester.map(() => ({ | |
type: UPLOAD_COMPLETE, | |
id | |
})), | |
sub.map(progress => ({type: PROGRESS_EVENT, payload: progress})) | |
) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment