暂时使用this样板并且一直使用普通JS对象作为存储/状态,直到我开始随机获得一些奇怪的突变,因此决定切换到Immutable.js。目前,我正在尝试将redux-immutable实施到我的代码中。我对react-router-redux和redux-immutable有一些问题;不幸的是,我不太了解这些图书馆,并且不知道这些图书馆。所以调试这个有很多麻烦。我已按照redux-immutable README中的说明进行操作。
在我的index.js文件中出现此错误。
未捕获的TypeError:无法读取属性' toJS'未定义的
index.js
const initialState = Immutable.Map({});
const store = configureStore(initialState);
const history = syncHistoryWithStore(hashHistory, store, {
selectLocationState (state) {
return state.getIn([
'route',
'location'
]).toJS();
}
});
render(
<Provider store={store}>
<Router history={history} routes={routes} />
</Provider>,
document.getElementById('root')
);
configureStore.js
const router = routerMiddleware(hashHistory);
const enhancer = compose(
applyMiddleware(thunk, router, logger),
DevTools.instrument(),
persistState(
window.location.href.match(
/[?&]debug_session=([^&]+)\b/
)
)
);
export default function configureStore(initialState) {
const store = createStore(rootReducer, initialState, enhancer);
if (module.hot) {
module.hot.accept('../reducers', () =>
store.replaceReducer(require('../reducers'))
);
}
return store;
}
rootReducer.js
import {combineReducers} from 'redux-immutable';
import routing from './Routing';
import Graphing from './Graphing';
import Syncing from './Syncing';
import Navigating from './Navigating';
import Notifying from './Notifying';
const rootReducer = combineReducers({
routing,
Graphing,
Navigating,
Syncing,
Notifying
});
export default rootReducer;
routing.js(路由缩减器)
import {LOCATION_CHANGE} from 'react-router-redux';
const initialState = Immutable.fromJS({
location: {}
});
export default (state = initialState, action) => {
if (action.type === LOCATION_CHANGE) {
return state.merge({
location: action.payload
});
}
return state;
};