【发布时间】:2017-07-31 02:40:07
【问题描述】:
这是我现在的传奇:
function* upAsyncSaga() {
yield takeEvery(UP_ASYNC, upAsyncHandler);
}
这里是相关的同步资料:
const UP_ASYNC = 'UP_ASYNC';
export function upAsync() {
return {
type: UP_ASYNC
}
}
function* upAsyncHandler() {
yield call(wait, 1000);
yield put(up());
}
const UP = 'UP';
export function up() {
return {
type: UP
}
}
我通过这样做store.dispatch(upAsync()) 触发upAsyncSaga。但是我想传递一个名为times 的参数。所以我想做store.dispatch(upAsync(3)) 然后我希望/想要像这个伪代码一样将参数传递给处理程序:
export function upAsync(times) { // this is the argument "times"
return {
type: UP_ASYNC
times // here it is again
}
}
function* upAsyncHandler(times) { // i want the argument to get to the handler
for (let i=0; i<times; i++) {
yield call(wait, 1000);
yield put(up());
}
}
这可能吗?
【问题讨论】:
标签: redux-saga