Skip to content

Commit

Permalink
starting redux (actions and reducers)
Browse files Browse the repository at this point in the history
  • Loading branch information
Universe-Man committed Jul 23, 2018
1 parent 01b0c4d commit ea66b65
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// export function addTodo(txt) {
// return {
// type: 'ADD_TODO',
// payload: txt,
// }
// }
21 changes: 20 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,27 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './assets/index.css';
import App from './App';
import reducer from './reducers/index.js'

import 'semantic-ui-css/semantic.min.css';

import { combineReducers, createStore } from 'redux';
import { createStore } from 'redux';




console.log('before createStore');

const store = createStore(reducer)

console.log(store);
console.log('after createStore', store.getState());

const action = {
type: "CLICK_EVENT", // ALL CAPS WITH _
}
store.dispatch(action);
console.log('after CLICK_EVENT', store.getState());


ReactDOM.render(<App />, document.getElementById('root'));
Expand All @@ -26,6 +43,8 @@ ReactDOM.render(<App />, document.getElementById('root'));

///////OLD REDUX SETUP/////////
//
// import { combineReducers, createStore } from 'redux';
//
// function usersReducer(state = [], action){
// return state;
// }
Expand Down
46 changes: 46 additions & 0 deletions src/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const initialState = {}

const renderState = {
loggedIn: false,
signingUp: false,
viewingProfile: false,
searching: false,
}

export const reducer = (state = initialState, action) => {
switch(action.type){
case "LOGGED_IN":
return {
...state,
...renderState,
loggedIn: true,
}
case "SIGNING_UP":
return { ...state,
...renderState,
signingUp: true,
}
case "VIEWING_PROFILE":
return { ...state,
...renderState,
viewingProfile: true,
}
case "SEARCHING":
return { ...state,
...renderState,
searching: true
}
return state;
}
}

export default reducer;

// HOW I HAD THE ORIGINAL THING
// case "SEARCHING":
// return { ...state,
// loggedIn: false,
// signingUp: false,
// viewingProfile: false,
// searching: true
// }

0 comments on commit ea66b65

Please sign in to comment.