Skip to content

Commit e68f373

Browse files
David TacoronteDavid Tacoronte
authored andcommitted
Continued updating Redux structure - createStore function is in place
1 parent fdf8862 commit e68f373

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {ActionTypes} from '../constants/action-types';
2+
3+
export const setProducts = (products) => {
4+
return {
5+
type: ActionTypes.SET_PRODUCTS,
6+
payload: products,
7+
};
8+
};
9+
10+
export const selectedProducts = (product) => {
11+
return {
12+
type: ActionTypes.SELECTED_PRODUCT,
13+
payload: product,
14+
};
15+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export const ActionTypes = {
2+
SET_PRODUCTS: "SET_PRODUCTS",
3+
SELECTED_PRODUCT: "SELECTED_PRODUCTS",
4+
REMOVE_SELECTED_PRODUCT: "REMOVE_SELECTED_PRODUCT"
5+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { combineReducers } from 'redux';
2+
import { productReducer } from "./productReducer"
3+
4+
const reducers = combineReducers ({
5+
allProducts: productReducer,
6+
});
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { ActionTypes } from "../constants/action-types";
2+
3+
const initialState = {
4+
products:[
5+
{
6+
id:1,
7+
title: "David",
8+
category: "Software Developer",
9+
10+
},
11+
],
12+
13+
};
14+
15+
export const productReducer = (state, { type, payload }) => {
16+
switch (type) {
17+
case ActionTypes.SET_PRODUCTS:
18+
return state;
19+
default:
20+
return state
21+
};
22+
};

0 commit comments

Comments
 (0)