Skip to content

Commit

Permalink
add comments to the file that sets up redux store
Browse files Browse the repository at this point in the history
  • Loading branch information
Rajatm544 committed Nov 4, 2021
1 parent bb0e360 commit f012882
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import {
orderListAllReducer,
} from './reducers/orderReducers';

// combine all the above reducers to the store
const reducer = combineReducers({
productList: productListReducer,
productDetails: productDetailsReducer,
Expand Down Expand Up @@ -65,22 +66,27 @@ const reducer = combineReducers({
orderListAll: orderListAllReducer,
});

// get a few cart items from the local storage
const cartItemsFromLocalStorage = localStorage.getItem('cartItems')
? JSON.parse(localStorage.getItem('cartItems'))
: [];

// get the user info from local storage
const userInfoFromLocalStorage = localStorage.getItem('userInfo')
? JSON.parse(localStorage.getItem('userInfo'))
: null;

// get the shipping address from local storage
const shippingAddressFromLocalStorage = localStorage.getItem('shippingAddress')
? JSON.parse(localStorage.getItem('shippingAddress'))
: {};

// get refresh token from the local storage
const tokenInfoFromLocalStoage = localStorage.getItem('refreshToken')
? localStorage.getItem('refreshToken')
: null;

// set the initial state based on above local storage values
const initialState = {
cart: {
cartItems: [...cartItemsFromLocalStorage],
Expand All @@ -94,8 +100,10 @@ const initialState = {
},
};

// user redux thunk for making async calls
const middleware = [thunk];

// create the redux store
const store = createStore(
reducer,
initialState,
Expand Down

0 comments on commit f012882

Please sign in to comment.