1
1
import React from 'react' ;
2
2
import ReactDOM from 'react-dom' ;
3
3
4
- import Root from './Root.jsx' ;
4
+ import { ReduxRouter } from 'redux-router' ;
5
+ import { Provider } from 'react-redux' ;
6
+
7
+ import routes from './routes.jsx' ;
8
+
9
+ import configureStore from './redux/configure-store.js' ;
5
10
6
11
//init httpService config
7
12
import httpServiceConfiguration from 'httpServiceConfiguration' ;
@@ -10,4 +15,55 @@ httpService.getInstance(httpServiceConfiguration);//will keep config in singleto
10
15
//this way, instead of using resolve.alias of webpack (and having the require of module messed up by webpack when they'll be executed server-side)
11
16
//I use dependency injection, in the one place that won't be executed in node : the client side bootstrap
12
17
13
- ReactDOM . render ( < Root /> , document . getElementById ( 'app-container' ) )
18
+ /** Redux initialization */
19
+
20
+ const component = (
21
+ < ReduxRouter >
22
+ { routes }
23
+ </ ReduxRouter >
24
+ ) ;
25
+
26
+ const initialState = { } ;
27
+
28
+ /**
29
+ * The whole store/reducers/actions creators configuration is done inside configureStore
30
+ * The configuration of the router is also done their since it's stored in redux store (using a specific reducer)
31
+ */
32
+ const store = configureStore ( initialState ) ;
33
+
34
+ let rootElement = null ;
35
+
36
+ /**
37
+ * Thanks to webpack.DefinePlugin which lets you inject variables at transpile time,
38
+ * everything inside the if statement will be dropped at minification if process.env.DEVTOOLS is set to false.
39
+ * This is why I don't use static ES6 import but CommonJS import (so that it will only get required in that particular case)
40
+ *
41
+ * Cause: since the following are debug tools, they are not meant to be a part of the production bundle (which makes it lighter)
42
+ *
43
+ * https://webpack.github.io/docs/list-of-plugins.html#defineplugin
44
+ */
45
+ if ( process . env . DEVTOOLS ) {
46
+ console . info ( 'redux devtools active, to hide the panel : ctrl+H - for more infos' , 'https://github.com/gaearon/redux-devtools' ) ;
47
+ const { DevTools, DebugPanel, LogMonitor } = require ( 'redux-devtools/lib/react' ) ;
48
+ rootElement = (
49
+ < Provider store = { store } >
50
+ < div >
51
+ { component }
52
+ < DebugPanel top right bottom >
53
+ < DevTools store = { store } monitor = { LogMonitor } />
54
+ </ DebugPanel >
55
+ </ div >
56
+ </ Provider >
57
+ ) ;
58
+ }
59
+ else {
60
+ console . info ( 'redux devtools not active, you can test them online at' , 'https://topheman.github.io/react-es6-redux/devtools.html' ) ;
61
+ console . info ( 'if you\'re testing the project in local, please refer to the README to activate them' ) ;
62
+ rootElement = (
63
+ < Provider store = { store } >
64
+ { component }
65
+ </ Provider >
66
+ )
67
+ }
68
+
69
+ ReactDOM . render ( rootElement , document . getElementById ( 'app-container' ) )
0 commit comments