-
-
Notifications
You must be signed in to change notification settings - Fork 15.2k
1.0 doc newcomer feedback #458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
For async the story is use redux-thunk or (even better in my opinion) use some form of redux promise middleware. We should definitely add docs for both those options and start adding some more basic async examples. For getting it working in the browser, we should probably also distribute a pre-built version and include some basic instructions for browserify/webpack. |
Thanks for the reply. I got around the "install" part (the surprising bit was that a pretty default setup of webpack does the trick - I was expecting to have something more to do.) Are there already promise middleware examples that you would recommend ? Looking forward to reading the updated docs. Thanks. |
The code I use is: function promiseMiddleware(store) {
return function (next) {
return function (action) {
action && typeof action.then === 'function'
? action.then(next, onError)
: next(action);
}
}
};
function onError(err) {
// use setTimeout to prevent error being silenced
setTimeout(function () {
throw err;
}, 0);
} You can then do async like: dispatch(
getJSON('/example.json').then(
data => (
{type: 'DATA_FETCH_COMPLETE', data: data}
),
err => (
{type: 'DATA_FETCH_FAILED', err: err}
)
)); |
How is it frustrating if it isn't written yet? I'm working on it. :-) |
In the meantime this might help you get started: https://gist.github.com/gaearon/074b0905337a6a835d82 Also: #99 |
Good to hear that ! It's frustrating because I fell like "telling people to use a flux-ish lib", without an example of "doing an ajax call the right way" in the doc, seems to be the norm those days. I've litteraly seen it with : redux, flummox, plain-old-flux and elm since I started looking into flux implementations. (EDIT : as pointed out, I dreamt the part about flummox. Poor little framework.) I tend to blame "todomvc" for that ; you don't need ajax to implement the "canonical" version, but it could be argued that such a backend-less single page app is going to be completely useless to a vast majority of developpers (who will have to call an API sooner than later.) Anyway, thanks for the help and good luck with the writing ! |
To be fair Flummox docs were focused on AJAX stuff from the start, from what I remember. |
@gaearon that's right, sorry. "Rant mode" makes you imagine things ;) |
@phtrivier +1 |
We just added two new examples focused on async interaction:
Feel free to check them out! |
Great ! #474 looks great (I had arrived at about this point, thanks to the other examples mentionned in this thread, but I did some weird things, and the organisation is clearer ) It's good that you introduce that "explicit" handling of sending a request / waiting for the response / getting the response and storing it / invalidating the cache. Although, is there a middleware / pattern that can remove some boilerplate for that ? Also, I'm not sure why you introduce "isomorphic-fetch" in the example (Is it just because you use it everywhere and want to prepare the ground for later examples ?) Will you be using those examples in the guide ? Thanks ! |
See "real-world" example. :-)
Yes. |
Can't wait to 😉 (will do as soon as I can !) Will you also touch on how you would test async actions (or is it out of scope ?) I would love to have your opinion on injecting / mocking / patching things like |
New doc is up: Async Actions. |
Thanks! |
@gaearon I'm trying to run
Any ideas? Thank you! |
I am really enjoying redux and react-redux, by the way. Great work! |
@gaearon Ok, running |
Should be solved by Async Actions.
We assume user is familiar with NPM ecosystem. We can't teach the user to use NPM and JavaScript bundlers—they'll have to get this knowledge elsewhere. We will provide a standalone build (#212) soon, but every Redux-related package is on NPM anyway so there's no point in resisting it.
Please raise a separate issue to discuss this. |
Hi
I've been checking the docs for redux 1.0, hoping to start using it.
Here is some feedback from total n00b :
I'm pretty sure're you're working on it, and from what I gathered the article seems to boil down to "use redux-thunk", but meanwhile a new user will have to guess and dive into examples without much direction
npm install redux
touse redux in a browser
. Maybe it's just a matter of knowing how to use webpack / browserify, and maybe I'm the last person who does not find it obvious ;)I hope it does not sound too much like a rant.
Thanks
The text was updated successfully, but these errors were encountered: