make it better

This commit is contained in:
Ray
2017-07-24 18:40:56 +01:00
commit 586fe2bec3
38 changed files with 4127 additions and 0 deletions

8
src/reducers/index.js Normal file
View File

@@ -0,0 +1,8 @@
import { combineReducers } from 'redux'
import product from './product_reducer'
const compareApp = combineReducers({
product
})
export default compareApp

View File

@@ -0,0 +1,26 @@
import * as types from '../constants/types';
const INITIAL_STATE = {
products: []
};
export default function (state = INITIAL_STATE, action) {
switch (action.type) {
case types.FETCH_PRODUCTS:
return {
...state, products: action.payload.map(product =>
({...product, compare: false})
)
};
case types.COMPARE_PRODUCT:
return {
...state, products: state.products.map(product =>
product.id === action.product.id ?
({...product, compare: !product.compare}) :
product
)
};
default:
return state;
}
}