Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

I'm using redux-saga to my web application.

I am using yield put and yield function for dispatching an action.

yield actioncreatorname(parameters) 
yield put(actioncreatorname(parameter))

please tell me difference between above two statements.

put is "putting" the action back into middleware. i tend to think of actions going into middleware as a message queue, so other sagas or reducers could be listening to that action and doing functions independent of this saga. – worc Apr 23, 2019 at 17:44

One of Redux-saga main benefits is that it has declarative effects (e.g put effect). Means that each effect contains some information to be interpreted by the middleware, and that information can be tested and asserted to match what we expected to happen.

The advantage of those declarative calls is that we can test all the logic inside a Saga by iterating over the Generator and doing a deepEqual test on the values yielded successively. This is a real benefit, as your complex asynchronous operations are no longer black boxes, and you can test in detail their operational logic no matter how complex it is.

To summarize, you can use actions directly instead of puting them. However, you won't benefit from the comfortability of testing it in a later stage.

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.