我发现不能在“meta.offline.effect”中触发一个动作。我们可以在“meta.offline.commit”和“meta.offline.rollback”中添加要触发的操作。我使用“redux-saga”向 API 发送调用并取回结果,现在我的应用程序正在离线模式下工作。
ex: export const addCustomer = (data) => {
return {
type: TYPES.ADD_CUSTOMER,
payload: { data },
meta: {
offline: {
effect: { },
commit: { type: "SUBMIT_CUSTOMER", meta: { data } },
rollback: { type: TYPES.SUBMIT_CUSTOMER, meta: { data } }
}
}
}
}
在传奇中:
function* submitCustomer(action) {
const data = { FirstName: action.meta.data };
const result = yield axios.post(`https://localhost:44300/api/Values/SubmitCustomer`, data)
.then(Response => Response).catch(error => {
throw error
});
}
function* customerSaga() {
yield takeEvery("SUBMIT_CUSTOMER", submitCustomer);
}
export default customerSaga;