-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathapp.js
41 lines (39 loc) · 1.15 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
*
* Created by erfli on 9/20/16.
*/
import React from 'react';
import createLogger from 'redux-logger';
import saga from 'redux-saga';
import sagaRoot from './sagas/index'
import {createStore, applyMiddleware, combineReducers} from 'redux';
import {Provider} from 'react-redux';
import story from './reducers/story';
import {zhihu} from './reducers/zhihu'
import Main from './Main';
const middlewares = [];
// 创建reducer
const rootReducer = combineReducers({story, zhihu});
// 创建中间件saga
const sagaMiddleware = saga();
middlewares.push(sagaMiddleware)
if (process.env.NODE_ENV === 'development') {
//创建中间件logger
const logger = createLogger();
middlewares.push(logger);
}
//applymiddleware配置中间件
const createStoreWithMiddleware = applyMiddleware(...middlewares)(createStore);
function createDefaultStore(initialsState) {
//通过reducer 获取stare
const defaultStore = createStoreWithMiddleware(rootReducer, initialsState);
return defaultStore;
}
const store = createDefaultStore();
sagaMiddleware.run(sagaRoot)
const Root = () => (
<Provider store={store}>
<Main />
</Provider>
);
export default Root;