Giter Club home page Giter Club logo

Comments (9)

navneet-g avatar navneet-g commented on May 21, 2024

Thanks @raRaRa for filing the issue. Please repro steps for redux-first-router. I will also take a look and see if we can create a high order function as you suggested, but that might take some time.

from redux-dynamic-modules.

raRaRa avatar raRaRa commented on May 21, 2024

Thanks for the quick response @navneet-g.

Currently redux-first-router requires you to connect routes, like so:

    const {
        reducer: rfrReducer,
        middleware: rfrMiddleware,
        enhancer: rfrEnhancer,
        thunk: rfrThunk,
    } = connectRoutes(history, routesMap, options)

This gives me a reducer, middleware and enhancer for redux-first-router.

What confuses me is whether or not I need to create a module for all reducers, e.g. am I required to create a module for the redux-first-router reducer, or can I simply pass the reducer to createStore?

My use case is that I have plenty of reducers that need to load on startup with the app, such as the user and router reducer. But at the same time I also want to load some reducers dynamically. So it's a bit annoying if I have to create a module for the startup reducers.

Thanks!

from redux-dynamic-modules.

navneet-g avatar navneet-g commented on May 21, 2024

You can create a single module with all the reducers, middlewares at the startup. e.g.

const startupModule = {
  "id":"startup-module",
   reducerMap: {
      rfr: frfReducer,
      user: userReducer
  },
  middlewares: [rfrMiddleware]
}

from redux-dynamic-modules.

raRaRa avatar raRaRa commented on May 21, 2024

Clever, thanks! One last question. RFR (Redux-first-router) has an enhancer, which is then composed to the middleware. How would this case be handled?

const middleware = applyMiddleware(...middlewares)
const enhancers = compose(rfrEnhancer, middleware)

from redux-dynamic-modules.

navneet-g avatar navneet-g commented on May 21, 2024

Second parameter to createStore function is enhancers, you can pass it there.

from redux-dynamic-modules.

navneet-g avatar navneet-g commented on May 21, 2024

Closing the issue as I have not heard any followup questions.

from redux-dynamic-modules.

raRaRa avatar raRaRa commented on May 21, 2024

Hey again @navneet-g. I had to take a pause on this task but I'm still trying to figure this out.

This is what I've got so far:

    // Configure Redux-First-Router (RFR), which gives back a RFR reducer, middleware and enhancer.
    const {
        reducer: rfrReducer,
        middleware: rfrMiddleware,
        enhancer: rfrEnhancer,
    } = connectRoutes(history, routesMap, options)

    // Here are my middlewares
    const middlewares = [
        userMiddleware,
        rfrMiddleware,
        thunk,
    ]

   // I want to have everything in my startup module to begin with
    const startupModule = {
        id: 'startup-module',
        reducerMap: {
            user,
            payments,
            location: rfrReducer,
        },
        middlewares: [...middlewares],
    }

    const store = createStore(
        preloadedState,
        [rfrEnhancer],
        [],
        startupModule,
    )

The solution above makes something crash inside Redux-First-Router, like something is not composed or configured properly. From the RFR documentations I need to compose the middlewares with the rfrEnhancer, like so:

    const middleware = applyMiddleware(...middlewares)
    const enhancers = compose(rfrEnhancer, middleware)

Should I pass enhancers instead of rfrEnhancer to the second parameter in createStore? It all feels a bit strange since I've already passed the middlewares to the startup module.

Thank you!

from redux-dynamic-modules.

raRaRa avatar raRaRa commented on May 21, 2024

I believe the issue is that the RFR enhancer expects rfrReducer's default state to be loaded into the store. But that doesn't happen until after @@Internal/ModuleManager/ModuleAdded.

from redux-dynamic-modules.

raRaRa avatar raRaRa commented on May 21, 2024

Is it possible to add reducers to the internal createStore?

from redux-dynamic-modules.

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.