Skip to content

Commit d6d0ae5

Browse files
committed
Merge pull request #1 from Solshal/setup
improve redux setup
2 parents 618d458 + 43ac399 commit d6d0ae5

File tree

10 files changed

+54
-42
lines changed

10 files changed

+54
-42
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ node_modules
2828

2929
# Bower
3030
bower_components/
31+
32+
.idea/

manifest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"default_popup": "index.html"
1111
},
1212
"permissions": [
13-
"activeTab"
13+
"activeTab",
14+
"storage"
1415
]
1516
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@
6767
"react": "^15.0.0",
6868
"react-dom": "^15.0.0",
6969
"react-redux": "^4.4.5",
70-
"redux": "^3.5.2"
70+
"redux": "^3.5.2",
71+
"redux-logger": "^2.6.1",
72+
"redux-thunk": "^2.1.0"
7173
}
7274
}

src/components/Main.js

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,10 @@ require('styles/App.css');
44
import React, { Component } from 'react';
55

66
class Main extends Component {
7-
constructor(props) {
8-
super(props);
9-
this.state = {
10-
status: false
11-
}
12-
}
13-
14-
componentDidMount() {
15-
this.setState({
16-
status: false
17-
});
18-
}
19-
207
render() {
21-
let status = this.state;
22-
238
return (
249
<div className="index">
25-
component did mount? {status}
10+
main content
2611
</div>
2712
);
2813
}

src/containers/App.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React, { Component } from 'react';
22
import { connect } from 'react-redux';
3-
import Main from '../components/Main';
3+
import Main from '../components/main';
44

55
class App extends Component {
66
render() {
@@ -9,8 +9,10 @@ class App extends Component {
99
}
1010

1111
function mapStateToProps(state) {
12-
const props = {};
13-
return props;
12+
let { auth } = state;
13+
return {
14+
auth: auth
15+
};
1416
}
1517

1618
export default connect(mapStateToProps)(App);

src/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React from 'react';
22
import { render } from 'react-dom';
33
import { Provider } from 'react-redux';
4-
import configureStore from './stores';
5-
import App from './containers/App';
4+
import configureStore from './stores/configureStore';
5+
import App from './containers/app';
66

77
const store = configureStore();
88

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const initialState = {
1111
isAuthenticated: loggedIn(),
1212
userId: getUserId(),
1313
username: getUserName()
14-
}
14+
};
1515

1616
function auth(state = initialState, action) {
1717
switch ( action.type ) {

src/reducers/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import { combineReducers } from 'redux';
2+
import Auth from './auth';
23

3-
const reducers = {};
4-
module.exports = combineReducers(reducers);
4+
export default combineReducers({
5+
Auth
6+
});

src/stores/configureStore.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { createStore, combineReducers, applyMiddleware } from 'redux';
2+
import thunk from 'redux-thunk';
3+
import createLogger from 'redux-logger';
4+
5+
// reducers combined
6+
import reducers from '../reducers/index';
7+
8+
let logger, store;
9+
10+
export default function configureStore(initialState) {
11+
if ( process.env.NODE_ENV !== 'production' ) {
12+
logger = createLogger();
13+
14+
store = createStore(reducers, initialState, applyMiddleware(
15+
thunk,
16+
logger
17+
));
18+
19+
} else {
20+
store = createStore(reducers, initialState, applyMiddleware(
21+
thunk
22+
));
23+
}
24+
25+
if (module.hot) {
26+
// Enable Webpack hot module replacement for reducers
27+
module.hot.accept('../reducers', () => {
28+
const nextReducer = require('../reducers');
29+
store.replaceReducer(nextReducer)
30+
})
31+
}
32+
33+
return store
34+
}

src/stores/index.js

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)