1
這是我的傳奇現在:參數傳遞到佐賀調度 - 並獲得參數的處理程序
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
}
}
我觸發upAsyncSaga
通過這樣做store.dispatch(upAsync())
。不過,我想通過一個名爲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());
}
}
這可能嗎?
謝謝Umesh,但我怎麼能得到'有效載荷'到'upAsyncHandler'? – Blagoh
非常感謝,我現在終於明白了。請原諒我延遲接受您的解決方案。 – Blagoh