-
Notifications
You must be signed in to change notification settings - Fork 2.5k
refactor(app): use react-fetcher for data fetching #531
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
Conversation
12a94bd to
cf34ec8
Compare
cf34ec8 to
4d85d7a
Compare
|
Thanks, @markdalgleish! Hopefully we will soon be migrating to |
|
Looks like I'll need to rework my PR once that's merged in. Also, the way that |
|
Sounds like a plan. Thanks for this! |
|
@markdalgleish this is awesome! Excited for when it comes in |
|
me too! now that react-router has a 2.0 release candidate i'm hoping to make this play nice with react-simple-router ... @jlongster ? |
|
Sorry this has taken so long to review--this looks good to me. A nice change =) Could you resolve conflicts and let me know when it's ready to merge? |
|
@andresgutgon they do serve a pretty similar need. the decorators of react-fetcher fit nicely with the style of RRUHE, but async-props is in the react-router/rackt family, nicely integrated with the routing we use. |
|
So we must choose one of then. Right? |
|
Guys, I thing both of them are not really good fit for this project to be honest. I almost finished async-props refactoring to better cover our needs. |
|
Wouldn't it be better to do a PR to async-props instead of doing a new package. I'm saying that because async-props is part of the rackt family and also it's related with redux. I don't know |
|
I would propose to make interface like that: It will block rendering until promise (or several promises) is completed You have this data in your redux state, so you can connect this date to another components as well What do you think? |
|
@andresgutgon It's too complex to my mind... And the main idea is to pass async data to props. I really prefer to keep data in redux state. It really simplifies this lib and provide you more flexibility |
|
I like your idea @sars |
|
Guys, have a look please: So, how it works: Server integration is really similar: Client integration too: Notice - you can pass any helpers, that could be useful for you in decorator You need to connect reducer as well: That's it... Now you can connect you data: https://github.com/sars/appetini-front/blob/appetini/src/containers/Home/Home.js#L13 They will be available in this.props in your component Under the hood: What do you think, guys? |
|
this looks great @sars! i'll have a look at bringing this into universal-redux shortly. |
|
@sars so now all redux async data like |
|
Yes, 'reduxAsyncConnect' |
|
Wow, good idea, @sars ! No more unnecessary actions creators and reducers. |
|
Hmm... that would end up mapping all of our async calls to Which could become: That way we could keep our existing logic for reducers? Alternatively, if this could export a formal Redux middleware, it could act as a replacement for ApiClient. |
|
@bdefore You can listen for actions in your own reducers, if you want. And receive, modify and store data as you like... Could you give me some example? |
|
Forgive my ignorance, but @markdalgleish what is the difference between react-fetchr and async-props other than react-fetchr (as far as I know) has the ability to prefetch or to defer while async-props only prefetchs? |
|
@mmahalwy, I made some comparison, have a look, please: |
|
FWIW, as a newbie trying to hook up SSR+react-router+redux for the first time, I really like the approach by @markdalgleish with react-fetcher (apparently now called redial). The main advantage I see is that it's super simple (it's basically just providing a mechanism to decorate your components and to query those decorations). Many of the related projects in this space seem to have been abandoned. I feel confident though that if redial is abandoned I could implement any bugfixes myself. I understand that redial by itself does not automagically integrate redux+react-router, whereas redux-async-connect does, but the examples given in the README of redial do show how to do that integration. Anyways, just thought I'd share my 2-cents as someone fresh to these concepts. |
|
@jbrantly redux-async-connect is really simple , see: |
I recently open sourced react-fetcher, a promise-based universal data fetching library. I noticed that your app basically uses the same pattern (including the separation between prefetching and deferring!), so I thought you might want to pull this functionality in from a library rather than embed it within the app.
What are your thoughts on this?