我试图通过最终效果将我的应用程序呈现到服务器端渲染(详细信息https://github.com/redux-saga/redux-saga/redux-saga/issues/issues/255,用解释为什么这么棘手)。
我的数据依赖于2个异步请求: getJwtToken -> (with token data) FetchItem -> now render
。
这完全可以吗?
我花了很多时间看频道(这里https://redux-saga.js.org/docs/advanced/channels.html),无法使用任何变化。
我的传奇看起来像这样(load_user_page最初是触发的)
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
Promise中。
不起作用,我的意思是动作JWT_REQUEST_SUCCESS
已发射,并且runSaga.done
承诺运行。但是我在console.log中的消息没有发出。
我认为,在同一函数中都有两个请求,但我正在尝试将令牌验证零件抽象。
不可能以任何方式吗?
真的卡住了。
编辑:解决方案是使用https://github.com/redux-saga/redux-saga/issues/255#issuecomment-323747994和https://githux-saga/redux-saga/redcaga/redux----saga/redux----saga/redrec.com/redrux--caga/redrux----SAGA/essugy/255#issuecomment-334231073。
ssr for All:)