redux infrastructure

master
Tudor Stanciu 2020-04-11 16:31:58 +03:00
parent 229691cbc7
commit f539da1f77
5 changed files with 43 additions and 3 deletions

View File

@ -4,10 +4,16 @@ import { BrowserRouter as Router } from "react-router-dom";
import "bootstrap/dist/css/bootstrap.min.css"; import "bootstrap/dist/css/bootstrap.min.css";
import App from "./components/App"; import App from "./components/App";
import "./index.css"; import "./index.css";
import configureStore from "./redux/configureStore";
import { Provider as ReduxProvider } from "react-redux";
const store = configureStore();
render( render(
<Router> <ReduxProvider store={store}>
<App /> <Router>
</Router>, <App />
</Router>
</ReduxProvider>,
document.getElementById("app") document.getElementById("app")
); );

View File

@ -0,0 +1,3 @@
export function createCourse(course) {
return { type: "CREATE_COURSE", course };
}

View File

@ -0,0 +1,14 @@
import { createStore, applyMiddleware, compose } from "redux";
import rootReducer from "./reducers";
import reduxImmutableStateInvariant from "redux-immutable-state-invariant";
export default function configureStore(initialState) {
const composeEnhancers =
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose; //add support for Redux dev tools
return createStore(
rootReducer,
initialState,
composeEnhancers(applyMiddleware(reduxImmutableStateInvariant()))
);
}

View File

@ -0,0 +1,9 @@
export default function courseReducer(state = [], action) {
switch (action.type) {
case "CREATE_COURSE":
return [...state, { ...action.course }];
default:
return state;
}
}

View File

@ -0,0 +1,8 @@
import { combineReducers } from "redux";
import courseReducer from "./courseReducer";
const rootReducer = combineReducers({
courses: courseReducer
});
export default rootReducer;