我正在尝试通过END effect(详细信息请参见
https://github.com/redux-saga/redux-saga/issues/255
,并解释为什么这是如此棘手)。
我的数据依赖于两个异步请求:
getJwtToken -> (with token data) FetchItem -> now render
这有可能吗?
我花了时间看频道(这里
https://redux-saga.js.org/docs/advanced/Channels.html
我的传奇故事看起来像这样(LOAD\u USER\u页面最初启动)
function* loadUserPage() {
yield put({type: 'JWT_REQUEST'})
const { response } = yield call(fetchJwtToken)
if (response) {
yield put({type: 'JWT_REQUEST_SUCCESS', payload: response})
}
}
function* fetchItem() {
console.log('NEVER GETS HERE')
}
function* watchLoadPage() {
yield takeLatest('LOAD_USER_PAGE', loadUserPage);
}
function* watchFetchItem() {
yield takeLatest('JWT_REQUEST_SUCCESS', fetchItem);
}
export default function* rootSaga() {
yield all([
fork(watchLoadPage)
fork(watchFetchItem)
])
}
runSaga().done
许诺
JWT_REQUEST_SUCCESS
被解雇
runSaga.done
我认为在同一个函数中包含两个请求是可能的,但我正在尝试提取令牌身份验证部分。
真的卡住了。