equal
deleted
inserted
replaced
|
1 import React, { Component } from 'react'; |
|
2 |
|
3 import thunkMiddleware from 'redux-thunk'; |
|
4 import { Provider } from 'react-redux'; |
|
5 import { createLogger } from 'redux-logger'; |
|
6 import { createStore, applyMiddleware, compose } from 'redux'; |
|
7 |
|
8 import { fetchAnnotations } from 'dashboard-components/lib/actions'; |
|
9 import rootReducer from 'dashboard-components/lib/reducers'; |
|
10 |
|
11 import { dashboardId } from './config.json'; |
|
12 |
|
13 let middlewares = [thunkMiddleware]; |
|
14 |
|
15 if (process.env.NODE_ENV !== 'production') { |
|
16 const loggerMiddleware = createLogger(); |
|
17 middlewares = [...middlewares, loggerMiddleware]; |
|
18 } |
|
19 |
|
20 /* eslint-disable no-underscore-dangle */ |
|
21 const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; |
|
22 /* eslint-enable */ |
|
23 |
|
24 const store = createStore( |
|
25 rootReducer, |
|
26 composeEnhancers(applyMiddleware(...middlewares)), |
|
27 ); |
|
28 |
|
29 export default WrappedComponent => class extends Component { |
|
30 componentWillMount() { |
|
31 const apiUrl = process.env.REACT_APP_API_URL; |
|
32 const discussionUrl = process.env.REACT_APP_DISCUSSION_URL; |
|
33 store.dispatch(fetchAnnotations(apiUrl, discussionUrl, dashboardId)); |
|
34 } |
|
35 |
|
36 render() { |
|
37 return <Provider store={store}><WrappedComponent {...this.props} /></Provider>; |
|
38 } |
|
39 }; |