Skip to content

Commit 7bbdc97

Browse files
author
Kingdom Orjiewuru
committed
feat: add babel and redux
1 parent 3a0cc6d commit 7bbdc97

File tree

8 files changed

+85
-3
lines changed

8 files changed

+85
-3
lines changed

package.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"devDependencies": {
1616
"babel-core": "^6.26.3",
1717
"babel-jest": "^23.4.2",
18-
"babel-loader": "^7.1.5",
18+
"babel-loader": "^8.0.6",
1919
"babel-polyfill": "^6.26.0",
2020
"babel-preset-env": "^1.7.0",
2121
"babel-preset-react": "^6.24.1",
@@ -36,8 +36,14 @@
3636
"webpack-dev-server": "^3.1.5"
3737
},
3838
"dependencies": {
39+
"@babel/core": "^7.4.5",
40+
"@babel/preset-env": "^7.4.5",
41+
"@babel/preset-react": "^7.0.0",
3942
"react": "^16.4.2",
40-
"react-dom": "^16.4.2"
43+
"react-dom": "^16.4.2",
44+
"react-redux": "^7.1.0",
45+
"redux": "^4.0.1",
46+
"redux-thunk": "^2.3.0"
4147
},
4248
"babel": {
4349
"presets": [

src/.babelrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"presets": ["@babel/preset-env", "@babel/preset-react"]
3+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { connect } from 'react-redux';
2+
import { sampleAction } from '../store/actions/sample.actions';
3+
4+
const SampleComponent = () => {};
5+
6+
const mapStateToProps = (state, ownProps) => {
7+
return {};
8+
};
9+
10+
const mapDispatchToProps = dispatch => {
11+
return {
12+
testSampleAction: dispatch(sampleAction())
13+
};
14+
};
15+
16+
export default connect(mapStateToProps, mapDispatchToProps)(SampleComponent);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// export all action types relating to this file in any case it's needed in other files
2+
export const SAMPLE_ACTION = 'SAMPLE_ACTION';
3+
export const SAMPLE_ACTION_WITH_PAYLOAD = 'SAMPLE_ACTION_WITH_PAYLOAD';
4+
5+
export const sampleAction = () => dispatch => {
6+
dispatch({
7+
type: SAMPLE_ACTION,
8+
});
9+
};
10+
11+
export const sampleActionWithPayload = () => dispatch => {
12+
const payload = {};
13+
14+
dispatch({
15+
type: SAMPLE_ACTION_WITH_PAYLOAD,
16+
payload,
17+
});
18+
};

src/app/store/configure-store.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createStore, applyMiddleware, compose } from 'redux';
2+
import thunk from 'redux-thunk';
3+
import rootReducer from './reducer';
4+
5+
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
6+
export default () => createStore(
7+
rootReducer,
8+
composeEnhancers(applyMiddleware(thunk)),
9+
);

src/app/store/reducer.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from 'redux';
2+
import sampleReducer from './reducers/sample.reducers';
3+
4+
export default combineReducers({
5+
sampleReducer,
6+
});
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as Actions from '../actions/sample.actions';
2+
3+
const initialState = {
4+
hasInitialState: true,
5+
};
6+
7+
const sample = (state = initialState, action) => {
8+
switch (action.type) {
9+
case Actions.SAMPLE_ACTION:
10+
return { nothing: null };
11+
case Actions.SAMPLE_ACTION_WITH_PAYLOAD:
12+
return {
13+
...state,
14+
dataFromWherever: action.payload,
15+
};
16+
default:
17+
return state;
18+
}
19+
};
20+
21+
export default sample;

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import 'babel-polyfill';
22
import React from 'react';
33
import ReactDOM from 'react-dom';
4+
import { Provider } from 'react-redux';
5+
6+
import configureStore from './app/store/configure-store';
47
import App from './app/App';
58
import './index.scss';
69

7-
export const Root = () => <App />;
10+
export const Root = () => <Provider store={configureStore()}><App /></Provider>;
811

912
ReactDOM.render(<Root />, document.getElementById('root'));

0 commit comments

Comments
 (0)