Closed meriadec closed 7 years ago
Maybe I'm not understanding the issue, but why can't you just write another action creator that dispatches the actions in the sequence you need them?
To be honest, making your hooks depend on each other doesn't sound like a good idea, but I'm not against providing an escape hatch if needed.
How about I provide a way to get an array of hook thunks, then you can trivially implement waterfall yourself, among other things. The API could look like this, for example (using promise-map-series):
import { triggerThunks } from 'redial';
import mapSeries from 'promise-map-series';
...
const fetchThunks = triggerThunks('fetch', components, locals);
mapSeries(fetchThunks, fn => fn())
.then(() => console.log('Done!'));
Actually waterfall is super needed on big projects. It's hard to use provideHooks
the route that i'm using is depending on other things, for ex:
I have profile page which there is nested route of profile/:id/comments
The comments has to be loaded only after profile has been loaded since it's use some of the profile responses to retrieve relevant comments.
In this example, you can see that waterfall is a must, and I can implement it by myself but then all the concept of provideHooks not working as expected
Is there a trigger function available yet for triggering the fetch hooks in sync (waterfall)? Of is there an alternative approach for this?
Hi, thanks for this awesome tiny tool :D
I've been stuck into a problem in a big web project recently, where I had some nested routes with hooks both on parent and children views (react-router). The children needed the parent data to be resolved before him, but it can't be guaranteed with a
Promise.all
call.So, I would find it very useful to have the ability to chain hooks instead of resolving them concurrently. This PR introduce the
waterfall
function, which is basically atrigger
, but with chained hooks (I trust components to appear in the right order : "outside" components first).I didn't achieve to write the correct test for it. Do you have time to help?