Skip to content

Commit

Permalink
setup redux reducers, actions, and store. Also moved App to component…
Browse files Browse the repository at this point in the history
…s folder
  • Loading branch information
ahorowitz123 committed Jul 20, 2018
1 parent aeea5ac commit 4162a3c
Show file tree
Hide file tree
Showing 10 changed files with 11,043 additions and 6 deletions.
10,979 changes: 10,979 additions & 0 deletions package-lock.json

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
6 changes: 6 additions & 0 deletions src/constants/actions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const ACTIONS = {
REPLACE_MOVIES: "REPLACE_MOVIES",
CHANGE_SELECTED: "CHANGE_SELECTED"
};

export default ACTIONS;
20 changes: 14 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import registerServiceWorker from './registerServiceWorker';
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./components/App";
import registerServiceWorker from "./registerServiceWorker";
import { Provider } from "react-redux";

ReactDOM.render(<App />, document.getElementById('root'));
import store from "./redux/store";

ReactDOM.render(
<Provider store={store}>
<App />
</Provider>,
document.getElementById("root")
);
registerServiceWorker();
11 changes: 11 additions & 0 deletions src/redux/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import ACTIONS from "../../constants";

const replaceMovies = newMovies => ({
type: ACTIONS.REPLACE_MOVIES,
newMovies
});

const changeSelected = newSelected => ({
type: ACTIONS.CHANGE_SELECTED,
newSelected
});
26 changes: 26 additions & 0 deletions src/redux/reducer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import ACTIONS from "../../constants/actions";

const initialState = {
movies: [],
selected: ""
};

/* Main reducer. */
const reducer = (state = initialState, action) => {
switch (action.type) {
case ACTIONS.REPLACE_MOVIES:
return {
...state,
movies: action.newMovies
};
case ACTIONS.CHANGE_SELECTED:
return {
...state,
selected: action.newSelected
};
default:
return state;
}
};

export default reducer;
7 changes: 7 additions & 0 deletions src/redux/store/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createStore } from "redux";

import reducer from "../reducer";

const store = createStore(reducer);

export default store;

0 comments on commit 4162a3c

Please sign in to comment.