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

Commit ca65416

Browse files
committed
优化入口文件
1 parent 1f39ff0 commit ca65416

File tree

2 files changed

+36
-40
lines changed

2 files changed

+36
-40
lines changed

src/entry.js

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import { createStore, applyMiddleware } from 'redux';
4-
import { Provider } from 'react-redux';
5-
import { composeWithDevTools } from 'redux-devtools-extension';
6-
import thunk from 'redux-thunk';
7-
import { ConnectedRouter, routerReducer, routerMiddleware, push } from 'react-router-redux';
8-
import { AppContainer } from 'react-hot-loader';
9-
import App from './App';
10-
import createHistory from 'history/createBrowserHistory';
11-
import rootReducer from './reducers/index';
12-
13-
var FastClick = require('fastclick');
1+
import React from 'react'
2+
import ReactDOM from 'react-dom'
3+
import { createStore, applyMiddleware, combineReducers } from 'redux'
4+
import { Provider } from 'react-redux'
5+
import { composeWithDevTools } from 'redux-devtools-extension'
6+
import thunk from 'redux-thunk'
7+
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux'
8+
import { AppContainer } from 'react-hot-loader'
9+
import App from './App'
10+
import createHistory from 'history/createBrowserHistory'
11+
import rootReducer from './reducers/index'
12+
13+
var FastClick = require('fastclick')
1414

1515
//按模块导入lodash,可以有效减小vendor.js的大小
16-
import isEmpty from 'lodash/isEmpty';
17-
import isEqual from 'lodash/isEqual';
18-
import debounce from 'lodash/debounce';
19-
import isArray from 'lodash/isArray';
16+
import isEmpty from 'lodash/isEmpty'
17+
import isEqual from 'lodash/isEqual'
18+
import debounce from 'lodash/debounce'
19+
import isArray from 'lodash/isArray'
2020

21-
window.isEmpty = isEmpty;
22-
window.isEqual = isEqual;
23-
window.debounce = debounce;
24-
window.isArray = isArray;
21+
window.isEmpty = isEmpty
22+
window.isEqual = isEqual
23+
window.debounce = debounce
24+
window.isArray = isArray
2525

26-
const history = createHistory();
26+
const history = createHistory()
2727
const middleware = routerMiddleware(history)
2828

2929
//解决移动端300毫秒延迟
30-
FastClick.attach(document.body);
31-
const middlewares = [thunk, middleware];
30+
FastClick.attach(document.body)
31+
const middlewares = [thunk, middleware]
3232

33-
const store = createStore(rootReducer, composeWithDevTools(applyMiddleware(...middlewares)));
33+
const store = createStore(
34+
combineReducers({routing: routerReducer, ...rootReducer}),
35+
composeWithDevTools(applyMiddleware(...middlewares))
36+
)
3437

3538
const render = Component =>
3639
ReactDOM.render(
@@ -40,13 +43,13 @@ const render = Component =>
4043
</Provider>
4144
</AppContainer>,
4245
document.getElementById('root')
43-
);
46+
)
4447

4548
render(App)
4649

4750
if(module.hot) {
4851
module.hot.accept('./App', () => {
4952
const NextRootContainer = require('./App').default
5053
render(NextRootContainer)
51-
});
54+
})
5255
}

src/reducers/index.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,10 @@
1-
import { combineReducers } from 'redux';
2-
import { routerReducer } from 'react-router-redux'
3-
4-
import { home } from './home';
5-
import { search } from './search';
6-
import { global } from './global';
7-
8-
//注册reducer,每个自定义的reducer都要来这里注册!!!不注册会报错。
9-
const rootReducer = combineReducers({
10-
routing: routerReducer,
1+
import { home } from './home'
2+
import { search } from './search'
3+
import { global } from './global'
4+
const rootReducer = {
115
/* your reducers */
126
home, //首页相关
137
search, //搜索相关
148
global
15-
});
16-
17-
export default rootReducer;
9+
}
10+
export default rootReducer

0 commit comments

Comments
 (0)