waiting for all actions to resolve
Closed this issue · 6 comments
I'm using redux-multi
to dispatch a loading state as per redux-effects-fetch
. I'm also using redial
to call the action and fetch the data before rendering on the server. redial
expects a promise and I don't really want to have to wrap some my dispatches with Promise.all()
.
Just wondering why d639ea7 was reverted?
The reasoning is discussed here: #2
Requiring a polyfill seemed like too big an ask for such a small library. However, you should be able to easily add a middleware that does this for you if you want:
function promisify () {
return next => action => Array.isArray(action)
? Promise.all(next(action))
: next(action)
}
Thanks!
Note to self: The above middleware must be placed before
redux-multi
in theapplyMiddleware()
call
Is it worth putting it in a npm module if a few people are using it?
@jameslnewell I'll take it!
What I need is that rendering only happens when both actions are reduced. Would this accomplish that?
@rkovacevic Nah, it's just going to return a Promise
from the dispatch()
method after both actions are dispatched - this is useful for UniversalJS apps that need to fetch data before rendering e.g. redial.
It won't accomplish that because Redux will still notify your connected components each time the state is updated (as each action is dispatched via the dispatch
method) and trigger a re-render (if your state has changed). You'll need to keep flags in your state to track whether the two actions are complete
For example, in the project I'm currently working on my state looks like this after I've fetched product and pricing data. When products.loaded && prices.loaded
I show the product information, otherwise I show a loading state.
const state = {
products: {
loaded: true,
...
},
prices: {
loaded: true,
...
}
};
Ok, thx for the update. I ended up using
'ReactDOM.unstable_batchedUpdates', until I figure out something better.
On Sun, Mar 13, 2016 at 11:04 PM, James Newell notifications@github.com
wrote:
@rkovacevic https://github.com/rkovacevic Nah, it's just going to
return a Promise from the dispatch() method after both actions are
dispatched - this is useful for UniversalJS apps that need to fetch data
before rendering e.g. redial https://github.com/markdalgleish/redial.It won't work because Redux will still notify your connected components
each time the state is updated (as each action is dispatched via the
dispatch method) and trigger a re-render (if your state has changed).
You'll need to keep flags in your state to track whether the two actions
are completeFor example, in the project I'm currently working on my state looks like
this after I've fetched product and pricing data. When products.loaded &&
prices.loaded I show the product information, otherwise I show a loading
state.const state = {
products: {
loaded: true,
...
},
prices: {
loaded: true,
...
}
};—
Reply to this email directly or view it on GitHub
#4 (comment).
Robert Kovačević
E-mail: robert.kovacevic1@gmail.com
Tel: +385 91 602 7569
Skype: robert.kovacevic1
LinkedIn: http://hr.linkedin.com/in/rkovacevic