import {combineReducers} from "redux";
function netstatus(state = {isLoading: false, isSuccess: true}, action) {
switch (action.type) {
case "NET_BEGIN":
return Object.assign({}, state, {
isLoading: true
});
break;
case "NET_OVER_SUCCESS":
return Object.assign({}, state, {
isLoading: false,
isSuccess: true
});
break;
case "NET_OVER_FAIL":
return Object.assign({}, state, {
isLoading: false,
isSuccess: false
});
break;
}
return state;
}
function user(state = {}, action) {
switch (action.type) {
case "LOGIN":
return Object.assign({}, state, action.data);
break;
}
return state;
}
function order(state = {userId: "", goods: []}, action) {
switch (action.type) {
case "GET_ORDER":
return Object.assign({}, state, action.data);
break;
case "ORDER_ADD":
return Object.assign({}, state, {
goods: [...state.goods, action.data]
});
break;
case "ORDER_RM":
return Object.assign({}, state, {
goods: state.goods.filter(good=> {
return good.id != action.data.id;
})
});
break;
}
return state;
}
function goods(state = [], action) {
switch (action.type) {
case "GET_GOODS":
return [...state, ...action.data];
break;
}
return state;
}
const reducer = combineReducers({
netstatus,
user,
order,
goods
});
module.exports = reducer;