markdalgleish / redial

Universal data fetching and route lifecycle management for React etc.
1.1k stars 42 forks source link

Handling async route rendering at the client #13

Closed autarc closed 8 years ago

autarc commented 8 years ago

The example shown for the client doesn't regard the asynchronous behavior of fetching data and updating the view. Since the emitter/trigger don't hook into the underlying lifecycle of the component, the initial rendering will be executed and finished before the provideHook promises are resolved. At the server side this can be controlled through a wrapped response, while at the client it seems to be more difficult. In case of React Router for instance its probably necessary to define the onEnter transitions and invoke their callbacks as the result of a successful promise chain. Any thoughts for a general implementation ?

svrcekmichal commented 8 years ago

@Autarc I have created new package, it's called reasync. It is in hard development but I believe this is one of the possible solutions how to handle pre and deferred fetching.

It's not clean, it's one of my first shots how i believe it can work, so PRs or at least issues are welcome. :)

autarc commented 8 years ago

@svrcekmichal Thanks, you actually pointed me in the right direction: using history.listenBefore instead of history.listen was a drop-in-replacement and solves the issue :+1:

Submitted an improved example.