Open MarcoScabbiolo opened 7 years ago
Hey,
I'm not sure I agree that it's essential. I use redux-saga, and at a pinch you could get away with just using promises and closures.
I have thought of making a generator that creates sagas in the same style that this generator does for containers etc, but just putting it out as a normal yeoman generator.
Perhaps you could do the same with redux-thunk?
@andytango The difference with redux-saga and redux-thunk is that the latter is very straight forward and no additional sub-generators would be needed to take full advantage of it, all you need is to import it as a middleware. Maybe a prompt "Would you like to use redux-thunk" that defaults to "no" could do the trick. It's not that redux-thunk is not widely used, it is mentioned in the official Redux docs.
Hey @MarcoScabbiolo yes I think those are fair points
+1
In fact this has been on my mind for quite some time. During setup as @MarcoScabbiolo describes.
Will see what I can do.
@MarcoScabbiolo if you by any chance already built that, feel free to submit a PR ;-)
@stylesuxx I don't have it ready yet, but I have some experiencie with generators and Inquirer, I might be able to get it done this weekend, If you are not already doing it let me know and i'll submit the PR when it's ready.
@MarcoScabbiolo, @stylesuxx I think we didn't need thunk
in this generator, because in this generator we are using bindActionCreators
and according to documentation bindActionCreators
wrapped into a dispatch call so they may be invoked directly.
am I right ?
@umair-khanzada bindActionCreators
calls your action creators forwarding the arguments and passes the resulting action to dispatch
, it doesn't pass dispatch
to the action creator to turn it into a thunk, for that you need redux-thunk
or redux-saga
or redux-loop
. Unless there is something else going on in bindActionCreators
but the documentation doesn't say anything about that.
@MarcoScabbiolo Yeah you are right I was confused, both are different concept, bindActionCreators
simply wrap action into dispatch.
Given that it is essential if you want to use asynchronous operations in actions, I think it would be nice to include redux-thunk. Maybe it's just me, but I end up adding it to every proyect. It is a very small dependency and as a middleware it's not invasive at all.
On top of including
redux-thunk
as a dependency, these would be the changes needed:At
generators/root/templates/store.js
:Add
import thunk from 'redux-thunk';
Change
import { createStore } from 'redux';
Toimport { createStore, compose, applyMiddleware } from 'redux';
And change:
To:
It could be implemented optionally with a prompt. What do you think? I can make the pull request if you're ok with this request.