Skip to content
This repository was archived by the owner on May 7, 2022. It is now read-only.

Commit f3e519b

Browse files
committed
add:immutable
1 parent d5a475a commit f3e519b

File tree

6 files changed

+1515
-1538
lines changed

6 files changed

+1515
-1538
lines changed

package.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"babel-runtime": "6.26.0",
2020
"case-sensitive-paths-webpack-plugin": "2.1.1",
2121
"chalk": "1.1.3",
22+
"connected-react-router": "^4.4.1",
2223
"create-portal": "^1.2.0",
2324
"css-loader": "0.28.7",
2425
"dotenv": "4.0.0",
@@ -33,8 +34,10 @@
3334
"extract-text-webpack-plugin": "^3.0.2",
3435
"file-loader": "1.1.5",
3536
"fs-extra": "3.0.1",
37+
"history": "^4.7.2",
3638
"html-webpack-plugin": "2.29.0",
3739
"http-proxy-middleware": "^0.18.0",
40+
"immutable": "^3.8.2",
3841
"jest": "20.0.4",
3942
"less": "^3.0.4",
4043
"less-loader": "^4.1.0",
@@ -55,9 +58,10 @@
5558
"react-router": "4.3.1",
5659
"react-router-dom": "4.3.1",
5760
"redux": "^4.0.0",
58-
"redux-devtools-extension": "^2.13.2",
61+
"redux-devtools-extension": "^2.13.5",
62+
"redux-immutable": "^4.0.0",
5963
"redux-localstorage": "^0.4.1",
60-
"redux-thunk": "^2.2.0",
64+
"redux-thunk": "2.3.0",
6165
"resolve": "1.6.0",
6266
"serve": "^6.5.6",
6367
"style-loader": "0.19.0",

src/index.js

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import React from 'react'
22
import ReactDOM from 'react-dom'
3-
import { createStore, applyMiddleware, combineReducers, compose } from 'redux'
3+
import { createBrowserHistory } from 'history'
4+
import { createStore, applyMiddleware, compose } from 'redux'
45
import { Provider } from 'react-redux'
5-
import persistState from 'redux-localstorage'
6-
import { composeWithDevTools } from 'redux-devtools-extension'
6+
import { connectRouter, routerMiddleware, ConnectedRouter } from 'connected-react-router/immutable'
7+
import Immutable from 'immutable'
8+
//import persistState from 'redux-localstorage'
79
import thunk from 'redux-thunk'
8-
// import BaseRouter from 'react-router-dom/HashRouter'
9-
import BaseRouter from 'react-router-dom/BrowserRouter'
1010
import App from './App'
1111
import rootReducer from './reducers/index'
1212
import initReactFastclick from 'react-fastclick'
@@ -16,23 +16,28 @@ import './app.less'
1616
//解决移动端300毫秒延迟
1717
initReactFastclick()
1818

19-
const middlewares = [thunk]
20-
21-
const enhancer = compose(
22-
persistState(/*paths, config*/)
23-
)
19+
const history = createBrowserHistory()
2420

21+
const initialState = Immutable.Map()
22+
const composeEnhancer = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose
2523
const store = createStore(
26-
combineReducers({ ...rootReducer }),
27-
composeWithDevTools(applyMiddleware(...middlewares), enhancer)
24+
connectRouter(history)(rootReducer),
25+
initialState,
26+
composeEnhancer(
27+
//persistState(/*paths, config*/), //数据持久化,暂时没有调通,备用状态
28+
applyMiddleware(
29+
routerMiddleware(history),
30+
thunk
31+
)
32+
)
2833
)
2934

3035
const render = Component =>
3136
ReactDOM.render(
3237
<Provider store={store}>
33-
<BaseRouter>
38+
<ConnectedRouter history={history}>
3439
<Component />
35-
</BaseRouter>
40+
</ConnectedRouter>
3641
</Provider>,
3742
document.getElementById('root')
3843
)

src/pages/Home/Home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const search = require('./files/search.svg')
2323

2424

2525
@connect(
26-
state => ({ ...state.home }),
26+
state => state.getIn(['home']),
2727
dispatch => bindActionCreators({ getBook, getNav }, dispatch)
2828
)
2929
class Home extends React.Component {

src/pages/Search/Search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import HotSearch from './components/HotSearch'
1313
import styles from './styles/search.less'
1414

1515
@connect(
16-
state => ({ ...state.search }),
16+
state => state.getIn(['search']),
1717
dispatch => bindActionCreators({ receiveHotSearch }, dispatch)
1818
)
1919
class Search extends React.Component {

src/reducers/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
import { combineReducers } from 'redux-immutable'
12
import { home } from './home'
23
import { search } from './search'
34
import { global } from './global'
4-
const rootReducer = {
5+
const rootReducer = combineReducers({
56
/* your reducers */
67
home, //首页相关
78
search, //搜索相关
89
global
9-
}
10+
})
1011
export default rootReducer

0 commit comments

Comments
 (0)