Comments (9)
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.
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.
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.
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.
Second parameter to createStore function is enhancers, you can pass it there.
from redux-dynamic-modules.
Closing the issue as I have not heard any followup questions.
from redux-dynamic-modules.
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.
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.
Is it possible to add reducers to the internal createStore?
from redux-dynamic-modules.
Related Issues (20)
- Is it possible to shave off React+ dependencies? HOT 1
- Could it be possible to provide simple Lit Element (Web Components) example
- support for nested reducers HOT 4
- Typing initialActions function
- [Examples] There is no 'enhancements' property
- [Examples] Unused argument 'getState'
- State and reducers are not removed when dynamic component unmounts HOT 2
- PENDING action is gone from sagas HOT 6
- remain module when component unmount HOT 2
- State lost, when moving from one module to another module HOT 1
- Remove module by id HOT 1
- modules are removed before useEffect cleanups are executed
- Update with React 16.x or 17.x
- takexxx saga(saga watched action) in different modules that have been loaded doesn't work in dynamic modules HOT 1
- Build pipeline failing for main
- Library abandoned? HOT 2
- TypeScript React: incorrect children props HOT 3
- This repo is missing important files HOT 3
- Module '"redux-dynamic-modules"' has no exported member 'IModule'.
- Any way to use the redux-toolkit with this lib? I have a code sample in the description..
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from redux-dynamic-modules.