Skip to content

Commit 49da88f

Browse files
committed
refactor(*) Major refactor of redux reducers/action creators now combined in modules #8
Reducers & action creators managing the same actions are now in the same modules, avoiding having `constants.js` file where you don't know anymore where they are used. Closing task #8 "Refactor Actions / Reducers" Added an .editorconfig file (since starting major rewrite - it's an opportunity to fix that)
1 parent debd8db commit 49da88f

23 files changed

+553
-491
lines changed

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# http://editorconfig.org
2+
root = true
3+
4+
[*]
5+
# change these settings to your own preference
6+
indent_style = space
7+
indent_size = 2
8+
9+
# it's recommend to keep these unchanged
10+
end_of_line = lf
11+
charset = utf-8
12+
trim_trailing_whitespace = true
13+
insert_final_newline = true
14+
15+
[*.md]
16+
trim_trailing_whitespace = false
17+
18+
[{package,bower}.json]
19+
indent_style = space
20+
indent_size = 2

src/Root.jsx

-63
This file was deleted.

src/actions/counter.js

-9
This file was deleted.

src/actions/searchUsers.js

-54
This file was deleted.

src/actions/singleUser.js

-96
This file was deleted.

src/bootstrap.jsx

+58-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
33

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';
510

611
//init httpService config
712
import httpServiceConfiguration from 'httpServiceConfiguration';
@@ -10,4 +15,55 @@ httpService.getInstance(httpServiceConfiguration);//will keep config in singleto
1015
//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)
1116
//I use dependency injection, in the one place that won't be executed in node : the client side bootstrap
1217

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'))

src/components/Github.jsx

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,29 @@ import SearchBox from './github/SearchBox.jsx';
88
import { connect } from 'react-redux';
99
import { bindActionCreators } from 'redux';
1010

11-
import * as SearchUsersActions from '../actions/searchUsers.js';
11+
import { changeUsername, findUsers } from '../redux/modules/multipleUsers.js';//import action creators
1212

1313
/**
1414
* This component holds the state, the component bellow only use props
1515
*/
1616

1717
@connect(
18-
(state) => ({state: state.searchUsers}),
19-
(dispatch) => bindActionCreators(SearchUsersActions, dispatch)
18+
(state) => ({multipleUsers: state.multipleUsers}),
19+
(dispatch) => bindActionCreators({ changeUsername, findUsers }, dispatch)
2020
)
2121
class Github extends React.Component {
2222
render(){
2323
//retrieve the actions now available in props thanks to connect and bindActionCreators, to pass it down to dumb components
24-
const { changeSearchUser, searchUsers } = this.props;
24+
const { changeUsername, findUsers } = this.props;
2525
//retrieving the state of the store passed via connect from the redux store - to pass it down to the dumb components
26-
let { state } = this.props;
26+
let { multipleUsers } = this.props;
2727
return (
2828
<div>
2929
<IntroBox/>
30-
<SearchBox changeSearchUser={changeSearchUser} searchUsers={searchUsers} {...state} />
30+
<SearchBox changeUsername={changeUsername} findUsers={findUsers} {...multipleUsers} />
3131
</div>
3232
);
3333
}
3434
}
3535

36-
export default Github;
36+
export default Github;

0 commit comments

Comments
 (0)