lexich/redux-api

How to include loading/progress indicators?

Open

#164 aperta il 4 ago 2017

Vedi su GitHub
 (4 commenti) (0 reazioni) (0 assegnatari)JavaScript (95 fork)batch import
help wanted

Metriche repository

Star
 (496 star)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

Sorry for the stupid question, but it seems I have to write a lot of code to simply show a loading indicator with redux-api. Is there a recommended approach?

What I tried:

Approach 1: Show and hide a loading indicator depending on the state of the metadata loading attribute. This approach takes a lot of code, because each resource in redux-api has its own loading attribute.

Approach 2: Dispatch SHOW/HIDE actions to toggle the loading indicator. I implemented this using the prefetch and postfetch hooks.

    prefetch: [
      function({actions, dispatch, getState}, cb) {
        dispatch(showLoading())
        cb()
      }
    ],
    postfetch: [
      function({data, actions, dispatch, getState, request}) {
        dispatch(hideLoading())
      }
    ]

But again I have to do this for each resource separately, which adds a lot of duplicated code to my reduxApi definition. I also have to deal with the callback chain, which seems odd, if I want to handle a loading indicator.

How do you guys do it? There must be a simple way to show a loading indicator with redux-api, right?

Guida contributor