【发布时间】:2017-10-06 11:48:39
【问题描述】:
我从 Reflux 来到 Redux。在 Reflux 中,您的业务逻辑仅存在于商店中,但在 Redux 中它似乎不同..例如在“Redux”中我有 “async-action”,我用“redux-thunk”实现了它。
在一种情况下,我想检查我的操作中的某些内容,如果需要,我向服务器发送请求并获取一些数据。在这种情况下,我必须检查我的操作中的逻辑,实际上我的业务逻辑存在于操作中并存储在一起,它不好..你的解决方案是什么?
例如,我有复选框,我检查了一些条件,如果结果为真,我向服务器发送请求,这是我的操作代码,正如您所见,我的业务逻辑在我的 Action 和 Reducer 上:
export function onCheckboxClick({itemId}) {
return (dispatch, getState) => {
let state = getState().get('myReducer');
let myConditionResult = state.get('foods').get(0).get('test');//for exmaple check some condition in my store
dispatch({type: 'CHECKBOX_CLICK', itemId});// for change the checkbox checked
if (myConditionResult) {
myApi.deleteOrderItem({itemId}).then(()=> {
dispatch({type: 'DELETE_ORDER_ITEM_FULFILLED', itemId});
}).catch((err)=> {
console.log(err);
dispatch({type: 'DELETE_ORDER_ITEM_REJECTED', itemId});
});
}
};
}
提前致谢
【问题讨论】:
-
在您发送一个发出 http 请求的操作之前,请更具体地说明必须满足哪些条件?
-
@meteorBuzz 感谢您的回复我更新了我的问题
标签: redux redux-thunk refluxjs