react-webpack-rails-tutorial icon indicating copy to clipboard operation
react-webpack-rails-tutorial copied to clipboard

Convert from redux-thunk to redux-saga

Open justin808 opened this issue 7 years ago • 7 comments

I'm looking for opinions here.

At team ShakaCode, we're using redux-saga rather than redux-thunk for new projects.

Options:

  1. Move existing code to redux-saga, and keep a non-router version of the code using redux-thunk. Basically, one more tab.
  2. Switch all the code to redux-saga.

References:

  • http://survivejs.com/blog/redux-saga-interview/
  • https://shift.infinite.red/using-redux-saga-to-simplify-your-growing-react-native-codebase-2b8036f650de#.jv5y7sgs1
  • http://stackoverflow.com/a/34933395/1009332

justin808 avatar Aug 10 '16 03:08 justin808

Check out this tutorial I made: https://forum.shakacode.com/t/experimenting-with-generators/657

justin808 avatar Aug 19 '16 10:08 justin808

As of right now, Thunk is easier to understand and debug. See #315. We should probably make a new project with thunk.

That being said, it's a great exercise to convert the 2 simple async calls to thunk in a PR.

justin808 avatar Aug 19 '16 10:08 justin808

I'll look at this issue

dzirtusss avatar Aug 20 '16 14:08 dzirtusss

See #325

justin808 avatar Aug 26 '16 09:08 justin808

Just curious, do you all find the conceptual overhead of redux-saga worth it?

I've used Thunks extensively in a production application, and have had no issues or complaints.

In terms of testability, it still seems like you have to manipulate generator internals, which seems like a leaky abstraction.

With Thunks, it seems like it would be possible to mock out XHR via Jest which would seem more straightforward.

I've also heard from less experienced members on my team that sagas were tough to debug and not as straightforward to use as Thunks.


Again, I don't have direct experience with sagas, just looking for an opinion from someone that's used both.

yangmillstheory avatar Oct 02 '16 22:10 yangmillstheory

@yangmillstheory You should be able to mock either the saga or thunk with jest. In terms of debugging, yes, the chrome debugger is not good inside of the generator function. You have to use print statements. I think they are both good ways.

justin808 avatar Oct 03 '16 00:10 justin808

This one should have gotten merged. Any takers that want to create an updated PR with this?

justin808 avatar Aug 09 '18 18:08 justin808