Comments (7)
I'm sorry I didn't make myself clear. What I meant is below:
import { createStore } from 'redux'
import { combineReducers } from 'redux-immutable'
import { Map } from 'immutable'
const reducerA = (state = "A", action) => state
const reducerB = (state = "B", action) => state
const createReducer = (additionalReducers) => {
return combineReducers({
...additionalReducers,
a: reducerA,
b: reducerB
})
}
// Create store with empty initial state
const store = createStore(createReducer(), Map({}))
console.log(store.getState().toJS())
// Then dynamically load another module with reducerC (e.g. via SystemJS System.import)
const reducerC = (state = "C", action) => state
const reducerD = (state = "D", action) => state
const newModuleReducer = combineReducers({
c: reducerC,
d: reducerD
})
// Add the loaded reducer to the store. The store structure should be:
// {
// a: "A",
// b: "B",
// inner: { c: "C", d: "D" }
// }
store.replaceReducer(createReducer({inner: newModuleReducer}))
console.log(store.getState().toJS())
This works OK with standard redux.
from redux-immutable.
What is the problem with explicitly passing Immutable.Map()
as the initial value?
from redux-immutable.
thats fine, just pointing out that without it, it throws an error and because of
reduxjs/redux#1189 (comment)
that maybe it should be possible to not specific an initialstate
from redux-immutable.
Shouldn't there be an option to let reducers (even those dynamically loaded) to define their initial state via default parameter ?
from redux-immutable.
Shouldn't there be an option to let reducers (even those dynamically loaded) to define their initial state via default parameter ?
Are you saying something different from what was already said?
from redux-immutable.
What is the problem with explicitly passing Immutable.Map() as the initial value?
The problem is when you dynamically load a module and want to updateReducers but don't what to update initialState (not sure if it's even possible but I'm not that familiar with redux yet). Plus your dynamically-loaded reducer is also produced by redux-immutable combineReducers.
from redux-immutable.
I am just not following you, at all. For me to further assist with this issue, I'd need a code example.
from redux-immutable.
Related Issues (20)
- React-router-redux selector documentation issue HOT 3
- Update from 3.0.9 to 3.0.10 causes flow-runtime errors HOT 1
- Link in README to combineReducers documentation is broken HOT 3
- Import state from redux-devtools not work HOT 4
- combineReducers not imported HOT 3
- Reducer is not a function (within state tree) HOT 1
- Add build option for es modules HOT 11
- State is undefined, can not get initial state HOT 2
- Trying to make it work with redux-auth
- Why can't I use Immutable.Record as initialState in rootReducer? HOT 6
- Changelog ? HOT 1
- please offer a browser built version HOT 6
- How to add non immutable store when combining reducers HOT 14
- bump dependancy to rc9 HOT 1
- Wrong return type of combineReducers HOT 10
- inputState.withMutations is not a function HOT 2
- Is this repo still maintained? HOT 2
- how to use redux hooks with redux-immutable? HOT 1
- Think I am seeing this too on IE11. This error HOT 1
- NPM release with the latest changes?
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-immutable.