React immutable (redux-immutable 统一数据格式)
https://www.cnblogs.com/nanianqiming/p/10356542.html https://www.jianshu.com/p/0c0786f119c7 https://blog.csdn.net/weixin_39786582/article/details/82623353 https://www.jianshu.com/p/5718c917d701 import immutable from "immutable"; const defaultState = immutable.fromJS({ name: "1", age: "2", sign: "3", list: [], flag: true, modifyIndex: -1, modifyItem: {} }) export default (state = defaultState, action) => { switch (action.type) { case "INPUT_CHANGE": switch (action.params) { case 1: return state.updateIn(["name"], (x) => x = action.value); case 2: return state.updateIn(["age"], (x) => x = action.value); case 3: return state.updateIn(["sign"], (x) => x = action.value); } case "TAB_ADD": var obj = { name: state.getIn(["name"]), age: state.getIn(["age"]), sign: state.getIn(["sign"]) }; return state.updateIn(["list"], (x) => x.push(obj)).setIn(["name"], "").setIn(["age"], "").setIn(["sign"], ""); //toJS toArry toObject fromJS // let newState = addState.toObject(); // newState.name = ""; // newState.age = ""; // newState.sign = ""; // return immutable.Map(newState); case "MODIFY_TAB": let newState = state.updateIn(["modifyIndex"], (x) => x = action.value); let obj = newState.getIn(["list"]) .getIn([action.value]); return newState.updateIn(["modifyItem"], (x) => x = obj).setIn(["flag"], false); case "MODIFY_CHANGE": switch (action.params) { case 1: return state.updateIn(["modifyItem", "name"], (x) => x = action.value); case 2: return state.updateIn(["modifyItem", "age"], (x) => x = action.value); case 3: return state.updateIn(["modifyItem", "sign"], (x) => x = action.value); } case "TAB_UPDATE": return state.updateIn(["list"],(x)=>x.splice(state.getIn(["modifyIndex"]),1,state.getIn(["modifyItem"]))) .setIn(["flag"],true) } return state; }