Comments (9)
The problem is that most code expects state.router to exist, however the new combineReducers you are using causes state to be a Map() which breaks access to state.router
You might just go back to the standard combine function or wrap the main reducer to inject the "router" attribute into the returned state
from redux-immutablejs.
Thanks @fgarcia. But if I use the standard combine function, how to make state immutable. Could you give me some code?
from redux-immutablejs.
I've just upgraded back to full Immutable state, so keep using the immutable combine and do this:
// DEFAULT const routerStateSelector = state => state.router;
const routerStateSelector = state => state.get('router');
// ...
reduxReactRouter({ routes, createHistory, routerStateSelector })
all credit goes to acdlite/redux-router#67 (comment)
from redux-immutablejs.
@fgarcia , I try your solution, like below
import { createStore, compose, applyMiddleware } from 'redux'
import { reduxReactRouter } from 'redux-router'
import createHistory from 'history/lib/createBrowserHistory'
import routes from './routes'
import { rootReducer } from './reducers' import thunk from 'redux-thunk'
import Immutable from 'immutable'
const state = Immutable.fromJS({})
const initialState = rootReducer(state)
const routerStateSelector = state => state.get('router')
const finalCreateStore = compose(
applyMiddleware(thunk),
reduxReactRouter({
routerStateSelector,
routes,
createHistory
})
)(createStore)
export default function configureStore () {
return finalCreateStore(rootReducer, initialState)
}
But it still not works...I debug in the routerStateReducer.js
file
function routerStateReducer(state, action) {
if (state === undefined) state = null;
var _extends2;
console.log(action); // add this
switch (action.type) {
case _constants.ROUTER_DID_CHANGE:
return action.payload;
case _constants.REPLACE_ROUTES:
if (!state) return state;
return _extends({}, state, (_extends2 = {}, _extends2[_constants.DOES_NEED_REFRESH] = true, _extends2));
default:
return state;
}
}
...
And the console prints
Object {type: "INIT"}
Object {type: "8.8.l.3.j.0.m.g.q.f.r"}
undefined
from redux-immutablejs.
@fgarcia @clinyong It should be state => state.get('router').toJS()
. redux-router needs a POJO.
from redux-immutablejs.
@neverfox only state is an ImmutableJS object, in my code the result of get already returns a POJO and I am already using this package combine function. Maybe is it different for the OP?
from redux-immutablejs.
Ah, I see. I had assumed that redux-immutablejs did a fromJS recursively. I don't use this library personally because I don't really see the advantage of making the top level state layer immutable (mainly because it breaks plugins like redux-router and redux-forms, without adding much benefit that I can see). I prefer to just apply ImmutableJS to the values of my top level state keys (in my custom reducers' initialState).
from redux-immutablejs.
@neverfox state => state.get('router').toJS()
is not the right way... The action
still be undefined.
This library seems too complicated for me, and I decide to use ImmutableJS just in reducers as @neverfox said.
Thanks guys.
from redux-immutablejs.
@clinyong I just took at stab at it by looking at the source code. @fgarcia is right that, at the very least, it doesn't need toJS()
but since it wasn't working for you even without that, I'm at a loss and don't really have much of a reason to pursue it any deeper. Good luck!
from redux-immutablejs.
Related Issues (20)
- Having trouble providing initial state to reducers HOT 2
- .map function always returns new object HOT 12
- Not installable from Git HOT 3
- redux 4.0 HOT 1
- Issues with initialState when using combineReducers HOT 1
- reducer must return immutable, how to handle js immutable types? HOT 2
- Is this still needed? HOT 2
- npm package cannot be used with Babel 6 HOT 1
- Steps to make it work with 'react-redux-universal-hot-example' HOT 1
- Consider deprecating in favour of redux-immutable HOT 4
- If I use the redux-immutablejs' createReducer(), will I still get back the initial state if the action is undefined as I would with a switch statement? HOT 1
- Discrepancy between github repo and published npm version HOT 3
- understanding effective use of (use-cases for) redux-immutablejs
- How to work with react-router-redux?
- combineReducers to return Immutable.Record instead of Immutable.Map
- TypeScript support?
- Link in README.md invalid
- OBSERVATION: fromJS in combineReducers not successfully converting to Map in node (but works in browser)
- Upgrading to immutable 4 HOT 1
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-immutablejs.