Redux boilerplate code

This commit is contained in:
Rodrigo Pedroso 2019-06-19 14:24:21 -04:00
commit 69d47c85f0
8 changed files with 12058 additions and 7 deletions

View file

@ -1,12 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
// import React from 'react';
// import ReactDOM from 'react-dom';
// import './index.css';
// import App from './App';
// 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
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA
serviceWorker.unregister();
// serviceWorker.unregister();

5
src/js/actions/index.js Normal file
View file

@ -0,0 +1,5 @@
import { ADD_ARTICLE } from "../constants/action-types"
export function addArticle(payload) {
return { type: "ADD_ARTICLE", payload }
}

View file

@ -0,0 +1 @@
export const ADD_ARTICLE = "ADD_ARTICLE"

6
src/js/index.js Normal file
View 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
View 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
View file

@ -0,0 +1,6 @@
import { createStore } from "redux"
import rootReducer from "../reducers/index"
const store = createStore(rootReducer)
export default store