Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how does one call a saga from within another saga?

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.

like image 430
Bennidhamma Avatar asked Mar 20 '17 00:03

Bennidhamma


People also ask

What is yield call in Saga?

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.

Can Yield * operator be used to compose multiple sagas in a sequential way?

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.

How do I dispatch action from Saga?

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.

What is generator function saga?

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.


1 Answers

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);
like image 133
Daniel Andrei Avatar answered Sep 23 '22 07:09

Daniel Andrei