Since the yield -statement is not allowed in the callback, how can I use the put function of the reduction saga in the callback?
I would like to have the following callback:
function onDownloadFileProgress(progress) {
yield put({type: ACTIONS.S_PROGRESS, progress})
}
This does not work and ends with an “unexpected token”, because yield is not valid in a simple function. Otherwise, I cannot pass the callback as a " function * ", which would allow me to get a return. ES6 seems broken here.
I read that in the redux saga there are some functions called " channels ", but to be honest, I did not understand. I read several times about these channels and sample code, but in all the examples they solved very complex and different problems, not my simple case, and in the end I got up there.
Can someone tell me how to solve this problem?
The whole context:
function onDownloadFileProgress(progress) {
yield put({type: ACTIONS.S_PROGRESS, progress})
}
export function * loadFile(id) {
let url = `media/files/${id}`;
const tempFilename = RNFS.CachesDirectoryPath + '/' + id;
const download = RNFS.downloadFile( {
fromUrl: url,
toFile: tempFilename,
background: false,
progressDivider: 10,
progress: onDownloadFileProgress,
})
yield download.promise;
}
source
share