Coder Social home page Coder Social logo

How to properly use resolvers about redux HOT 4 OPEN

mczp avatar mczp commented on May 8, 2024
How to properly use resolvers

from redux.

Comments (4)

mczp avatar mczp commented on May 8, 2024

After tinkering I figured a way to access the API from the injected transition, however I would still be interested about how to reconcile redux with the resolvers via action creators and reducers

from redux.

 avatar commented on May 8, 2024

Don't know if this is the recommended way however I found that dependency injection is a bad idea, on the other side resolvers can be easily reconciled with the redux store, below is an example of a simple config I'm using:

import FabricsList from './components/fabric_list'

import { api } from 'api/wsrpc'
import { store } from 'app/store'
import { BROCADE_GET_FABRICS } from './actions/types'

// Configuration for routes [states]
export const states = [{
  name: 'app.fabrics',
  url: '/fabrics',
  resolve: [
    {
      token: 'fabrics',
      resolveFn: function () {
        // An API method which returns a promise
        let p = api.sendRequest(BROCADE_GET_FABRICS)
        // Register the callback to update redux store when promise gets resolved
        p.then((data)=> {
          store.dispatch({type: BROCADE_GET_FABRICS, data})
        })
        return p
      }
    }
  ],
  component: FabricsList,
}]

from redux.

elbaro avatar elbaro commented on May 8, 2024

Is there any other way to access dispatch() and avoid import store singleton?

from redux.

 avatar commented on May 8, 2024

Technically yes, you can inject it into the router and use dependency injection to resolve it in the router resolve function. There might be another way perhaps by using redux bindActionCreators however on the doc page it says:

Normally you should just call dispatch directly on your Store instance. 
If you use Redux with React, react-redux will provide you with the dispatch 
function so you can call it directly, too.

So apparently it is normal to pass the singleton around...

from redux.

Related Issues (10)

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.