Redux boilerplate code
This commit is contained in:
parent
b794708e2e
commit
69d47c85f0
8 changed files with 12058 additions and 7 deletions
12009
package-lock.json
generated
Normal file
12009
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
|
@ -3,6 +3,7 @@
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@babel/runtime": "^7.4.5",
|
||||||
"react": "^16.8.6",
|
"react": "^16.8.6",
|
||||||
"react-dom": "^16.8.6",
|
"react-dom": "^16.8.6",
|
||||||
"react-scripts": "3.0.1"
|
"react-scripts": "3.0.1"
|
||||||
|
@ -27,5 +28,9 @@
|
||||||
"last 1 firefox version",
|
"last 1 firefox version",
|
||||||
"last 1 safari version"
|
"last 1 safari version"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"react-redux": "^7.1.0",
|
||||||
|
"redux": "^4.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
16
src/index.js
16
src/index.js
|
@ -1,12 +1,14 @@
|
||||||
import React from 'react';
|
// import React from 'react';
|
||||||
import ReactDOM from 'react-dom';
|
// import ReactDOM from 'react-dom';
|
||||||
import './index.css';
|
// import './index.css';
|
||||||
import App from './App';
|
// import App from './App';
|
||||||
import * as serviceWorker from './serviceWorker';
|
// import * as serviceWorker from './serviceWorker';
|
||||||
|
import index from './js/index'
|
||||||
|
|
||||||
ReactDOM.render(<App />, document.getElementById('root'));
|
// ReactDOM.render(<App />, document.getElementById('root'));
|
||||||
|
|
||||||
// If you want your app to work offline and load faster, you can change
|
// If you want your app to work offline and load faster, you can change
|
||||||
// unregister() to register() below. Note this comes with some pitfalls.
|
// unregister() to register() below. Note this comes with some pitfalls.
|
||||||
// Learn more about service workers: https://bit.ly/CRA-PWA
|
// Learn more about service workers: https://bit.ly/CRA-PWA
|
||||||
serviceWorker.unregister();
|
// serviceWorker.unregister();
|
||||||
|
|
||||||
|
|
5
src/js/actions/index.js
Normal file
5
src/js/actions/index.js
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { ADD_ARTICLE } from "../constants/action-types"
|
||||||
|
|
||||||
|
export function addArticle(payload) {
|
||||||
|
return { type: "ADD_ARTICLE", payload }
|
||||||
|
}
|
1
src/js/constants/action-types.js
Normal file
1
src/js/constants/action-types.js
Normal file
|
@ -0,0 +1 @@
|
||||||
|
export const ADD_ARTICLE = "ADD_ARTICLE"
|
6
src/js/index.js
Normal file
6
src/js/index.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import store from "../js/store/index"
|
||||||
|
import { addArticle } from "../js/actions/index"
|
||||||
|
|
||||||
|
window.store = store
|
||||||
|
|
||||||
|
window.addArticle = addArticle
|
17
src/js/reducers/index.js
Normal file
17
src/js/reducers/index.js
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
import { ADD_ARTICLE } from "../constants/action-types"
|
||||||
|
|
||||||
|
const initialState = {
|
||||||
|
articles: []
|
||||||
|
}
|
||||||
|
|
||||||
|
function rootReducer(state = initialState, action) {
|
||||||
|
if (action.type === ADD_ARTICLE) {
|
||||||
|
return Object.assign({}, state, {
|
||||||
|
articles: state.articles.concat(action.payload)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
return state
|
||||||
|
}
|
||||||
|
|
||||||
|
export default rootReducer
|
6
src/js/store/index.js
Normal file
6
src/js/store/index.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
import { createStore } from "redux"
|
||||||
|
import rootReducer from "../reducers/index"
|
||||||
|
|
||||||
|
const store = createStore(rootReducer)
|
||||||
|
|
||||||
|
export default store
|
Loading…
Add table
Add a link
Reference in a new issue