Javascript hanlde使用saga和axios上传进度
我试图在react中创建进度条。上传文件后,出现以下错误: 错误:调用:{context,fn}类型的参数未定义或为nullJavascript hanlde使用saga和axios上传进度,javascript,reactjs,react-redux,redux-saga,saga,Javascript,Reactjs,React Redux,Redux Saga,Saga,我试图在react中创建进度条。上传文件后,出现以下错误: 错误:调用:{context,fn}类型的参数未定义或为nullfn saga.js: const identity = a => a; const createAsync = file => { let emit; const chan = eventChannel(emitter => { emit = emitter; return () => {}; }); const
fn
saga.js:
const identity = a => a;
const createAsync = file => {
let emit;
const chan = eventChannel(emitter => {
emit = emitter;
return () => {};
});
const promise = uploadVideoApi(file, function(e) {
emit((e.loaded * 100) / e.total);
});
return [promise, chan];
};
function* watchOnProgress(chan) {
while (true) {
const data = yield take(chan);
yield put(uploadFileProgress(data));
}
}
function* uploadVideo({ file }) {
const [promise, chan] = createAsync(file);
yield fork(watchOnProgress, chan);
const result = yield call(identity(promise));
}
actions.js:
export function uploadFileProgress(percent) {
return {
type: UPLOAD_VIDEO_PROGRESS,
percent,
};
}
call
来自哪里?如果您打算使用Function.prototype.call()
,那么您需要知道这是一种只能在函数实例上运行的方法,在这种情况下,identity.call(promise)
?调用文档:@DoriAviram它来自redux saga effects。来源:你不能在承诺中使用call
。如果您想等待承诺,只需执行屈服承诺
参考此处:可能是重复问题