bananaoomarang / isomorphic-redux

Isomorphic Redux demo, with routing and async actions
https://medium.com/@bananaoomarang/handcrafting-an-isomorphic-redux-application-with-love-40ada4468af4
MIT License
455 stars 87 forks source link

How to show loading state? #54

Closed yrik closed 8 years ago

yrik commented 8 years ago

Can't figure out how to show progress indicator while ajax requests.

What is the best way to handle that? Should I fire extra action that set isLoading: true when I start request and then extra action to set isLoading: false?

bananaoomarang commented 8 years ago

This is what I do, just put it in the promiseMiddleware.

Here’s an example: https://github.com/bananaoomarang/chapters/blob/master/shared/lib/promiseMiddleware.js

I handle it in the a SessionReducer, along with user/login state and whatever else.

yrik commented 8 years ago

Thank you!

yrik commented 8 years ago

@bananaoomarang it's became more interesting when I want to show several loading indicators for different areas :)

Dattaya commented 8 years ago

@yrik you can set isLoadingSomething flag manually in a reducer. Set it to true on LOAD_SOMETHING_REQUEST and remove on LOAD_SOMETHING + LOAD_SOMETHING_FAILURE