Coder Social home page Coder Social logo

Comments (24)

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Could you provide more info about your setup? Do you dispatch _FULFILLED or _REJECTED actions at the end of async events?

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

yes I have dispatched _FULFILLEd or _REJECTED action, the loadingBarReducer is executing and in case HIDE i'm getting newstate = 1. actually on page load there are several ajax call executing

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Please make sure the you call _FULFILLED or _REJECTED the same amount of times as _PENDING. Basically speaking, the Loading Bar will be shown until all ajax request complete.

If you want to forcefully hide Loading Bar, you can call resetLoading() at any time.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

I tried resetLoading() but it is throwing error Uncaught (in promise) TypeError: (0 , _reactReduxLoadingBar.resetLoading) is not a function

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

Please show me the code you're using.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024
   import { showLoading, hideLoading, resetLoading } from 'react-redux-loading-bar';

     export default function loadingBarMiddleware(config = {}) {
     return (store) => next => (action) => {
      console.log('dispatch', action);

      const isPending = new RegExp(`_FETCHING_`, 'g')
      const isFulfilled = new RegExp(`_FETCHED_`, 'g')
      const isRejected = new RegExp(`_FETCH_.*_FAILED`, 'g')


    if (action.type.match(isPending)) {
        store.dispatch(showLoading())
    } else if (action.type.match(isFulfilled) ||
        action.type.match(isRejected)) {
        store.dispatch(hideLoading())
        //store.dispatch(resetLoading())
    }
    return next(action);
}}

from here I'm dispatching the actions..

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Well, apparently I forgot to export resetLoading action. I just published the v2.6.5, please give it a try.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

ok :)

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

Yeah that error has gone... but still hideLoading is not hiding the loading bar

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

Could you check what is in the store?

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

@mironov : but show and hide action are executing same number of time...

I debug it ... in the end I'm getting newState = 1 when case is Hide in loadingBarReducer()

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

@mironov i checked store and get loadingBar: 2

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

resetLoading explicitly sets the counter to 0.
If the counter is > 0 that might mean that showLoading has been called after resetLoading.

Could you check the order of actions that were dispatched using redux logger middleware?

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

Yeah sequence is somethig like this.

loading-bar/SHOW ---> loading-bar/HIDE ---> loading-bar/SHOW ---> loading-bar/HIDE and at last newState is 1

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

In that case the counter should be 0. Please make sure there're no more loading bar related actions dispatched.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

when the first time showLoading() is called loadingBar: 2 in store , I think it should be 1

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

Yes it should be 1. Please check your initial state of the store when the app is being loaded.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

initially the state is 0 ---> then it become 1 ---> then loading-bar/SHOW action executes which makes it 2.

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

When you say "then it become 1" — what do you mean? What action makes the counter to become 1?

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Something is changing the counter to 1 before showLoading kicks in. I can take a look deeper if you can push related code to a repo or gist.

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Do you use the bundled loadingBarReducer or a custom one? It looks like the loadingBarReducer returns 1 on store initialization.

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

from react-redux-loading-bar.

ashwintastic avatar ashwintastic commented on May 27, 2024

@mironov :

Here at store initialization arguments[0] contains 1 when the action type is @@redux/PROBE_UNKNOWN_ACTION_9.o.0.b.b.5.1.k.b.6.7.k.q.0.8.u.x.r

      function loadingBarReducer() {
         var state = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0; 
        var action = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
       var newState = void 0;
      switch (action.type) {
        case SHOW:
        newState = state + 1;
         break;
        case HIDE:
        newState = state > 0 ? state - 1 : 0;
        break;
       case RESET:
        newState = 0;
        break;
       default:
    return state;
   }
 return newState;
  }

from react-redux-loading-bar.

mironov avatar mironov commented on May 27, 2024

@ashwinimnnit Could you show your combineReducers function?

from react-redux-loading-bar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.