redux infrastructure
parent
229691cbc7
commit
f539da1f77
|
@ -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(
|
||||||
|
<ReduxProvider store={store}>
|
||||||
<Router>
|
<Router>
|
||||||
<App />
|
<App />
|
||||||
</Router>,
|
</Router>
|
||||||
|
</ReduxProvider>,
|
||||||
document.getElementById("app")
|
document.getElementById("app")
|
||||||
);
|
);
|
||||||
|
|
|
@ -0,0 +1,3 @@
|
||||||
|
export function createCourse(course) {
|
||||||
|
return { type: "CREATE_COURSE", course };
|
||||||
|
}
|
|
@ -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()))
|
||||||
|
);
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
export default function courseReducer(state = [], action) {
|
||||||
|
switch (action.type) {
|
||||||
|
case "CREATE_COURSE":
|
||||||
|
return [...state, { ...action.course }];
|
||||||
|
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,8 @@
|
||||||
|
import { combineReducers } from "redux";
|
||||||
|
import courseReducer from "./courseReducer";
|
||||||
|
|
||||||
|
const rootReducer = combineReducers({
|
||||||
|
courses: courseReducer
|
||||||
|
});
|
||||||
|
|
||||||
|
export default rootReducer;
|
Loading…
Reference in New Issue