Я бы хотел назвать сагу из другой саги.И наконец я понял!Просто используйте функции call
и select
.Но мой подход выглядит не очень хорошо:
// language: TypeScript
import { call, put, select } from 'redux-saga/effects'
// ... snip ...
// A "saga" that does "something"
export function* doSomething(action: DoSomethingAction) {
const { filterId } = action.payload
try {
// calls the getSomething "saga" and then
// retrieves the 'item' from the store.
yield call(getSomething, { type: 'GET_SOMETHING', payload: { id: filterId } })
const item = yield select((state: AppState) => state.item)
// after retrieving the item from the store
// we can now call an end-point provider
const res = yield call(createSomethingRequest, item.aNeededProperty)
yield put(createSomethingSuccess(res.data))
} catch (error) {
yield put(createSomethingFail(error))
}
}
Есть ли альтернативный и более элегантный способ вызвать сагу из другой саги и извлечь что-то из магазина?