【发布时间】:2017-08-19 07:12:31
【问题描述】:
由于回调中不允许使用“yield”-statement,我如何在回调中使用 redux-saga 的“put”功能?
我想要以下回调:
function onDownloadFileProgress(progress) {
yield put({type: ACTIONS.S_PROGRESS, progress})
}
这不起作用并以“意外令牌”告终,因为 yield 在普通函数中是不允许的。否则我不能将回调作为“function *”传递,这将允许屈服。 ES6 在这里似乎坏了。
我读到 redux-saga 提供了一些称为“channels”的功能,但说实话,我没有明白。我已经多次阅读这些渠道和示例代码,但在所有示例中,它们都解决了非常困难和不同的问题,而不是我的简单案例,最终我已经站起来了。
谁能告诉我如何处理这个问题?
整个上下文:
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;
}
【问题讨论】:
-
不允许你不能
-
你想说什么?有什么不同吗?
标签: javascript ecmascript-6 redux yield redux-saga