When using redux-connect (the @asynConnect attribute) how does one chain a second saga, that is dependent on a successful completion of the first saga?
Just simply putting
the saga dispatch action in at the appropriate location in the first saga works on the client, but not on the server.
In this above example, we yield call . call is a blocking effect creator. This means that the saga will not continue to run to the next yield until the API call finishes. Once it's finished, we yield put . put is dispatching a new action with the result from the previous yield.
You can use the builtin yield* operator to compose multiple Sagas in a sequential way. This allows you to sequence your macro-tasks in a procedural style. Note that using yield* will cause the JavaScript runtime to spread the whole sequence.
Create a plain JavaScript Object to instruct the middleware that we need to dispatch some action, and let the middleware perform the real dispatch. This way we can test the Generator's dispatch in the same way: by inspecting the yielded Effect and making sure it contains the correct instructions.
Sagas are implemented as Generator functions that yield objects to the redux-saga middleware. The yielded objects are a kind of instruction to be interpreted by the middleware. When a Promise is yielded to the middleware, the middleware will suspend the Saga until the Promise completes.
Calling a saga from another saga is as simply as doing a call effect.
yield call(firstSaga, params);
For example:
yield call(firstSaga);
//do something in current saga with whatever you save
//from the first saga in redux store
const data = select(firstSagaSelector);
yield call(myApi, data);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With