GithubHelp home page GithubHelp logo

Comments (2)

tomatau avatar tomatau commented on May 18, 2024

I think I get the reasoning for this, although I haven't gone down this more 'global' path for managing errors or loading state for the app. I tend to keep to local state.

Personally, I think this API addition would be a little bit too unique to implementation details. Many apps out there could be taking completely different approaches to tackle the same problem. Also, if I was coming fresh into a new project with requests: true, it wouldn't be super obvious that this was making the global loading spinner work correctly -- and visa versa.

So, I tend to favour more compositional approaches, such as the middleware you have described... or even, to be super explicit... having the regex match against action.type performed in a globalState reducer:

const defaultState = { isError: false, isLoading: false };
const globalStateReducer = (state=defaultState, action) => {
   switch (true) {}
    case action.type.match(pending_regex):
      return { ...state, isLoading: true }
    case action.type.match(rejected_regex):
      return { ...state, isError: true }
    default:
      return state;
   }
}

I find this approach more explicit. Although, it requires some synchronisation between the different actionTypeSuffixes and the regex checks.

But overall, happy to let the wider community decide :)

from redux-promise-middleware.

pburtchaell avatar pburtchaell commented on May 18, 2024

I think you make a good point. 💯 I am going to revisit my implementation of this with your suggestion to move the regex into the reducer.

from redux-promise-middleware.

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.