-
-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About initialState #21
Comments
What is the problem with explicitly passing |
thats fine, just pointing out that without it, it throws an error and because of |
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? |
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. |
I am just not following you, at all. For me to further assist with this issue, I'd need a code example. |
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. |
I am wondering why redux-immutable has no default state.
redux-immutable/src/combineReducers.js
Line 13 in ac78103
Redux
combineReducers
has a default value. https://github.com/reactjs/redux/blob/6870b826b6b1bea7e7aec67a4ed88d139bd382cd/src/combineReducers.js#L111I tried to nest
redux-immutable
combineReducers
but it throwsCannot read property 'withMutations' of undefined
because I did not specify the nested property in my globalinitialState
Object.Shouldn't it work without specifying the
initialState
.The text was updated successfully, but these errors were encountered: