import { CHANGE_INPUT, ADD_ITEM, DELETE_ITEM } from "./store/actionsTypes"; const defaultState = { inputValue: "Write Something修改版", list: ["数组第一条", "数组第二条", "数组第三条", "数组第四条"], }; export const reducer = (state = defaultState, action) => { // console.log(state, action); //reducer 里 只能接收state,不能改变state if (action.type === CHANGE_INPUT) { let newState = JSON.parse(JSON.stringify(state)); newState.inputValue = action.value; return newState; } if (action.type === ADD_ITEM) { let newState = JSON.parse(JSON.stringify(state)); newState.list.push(newState.inputValue); newState.inputValue = ""; // console.log("newState.inputValue", "2" + newState.inputValue + "2"); // console.log("newState.list", newState.list); return newState; } if (action.type === DELETE_ITEM) { let newState = JSON.parse(JSON.stringify(state)); newState.list.splice(action.index, 1); return newState; } return state; }; //仓库