我有一个 redux-saga 如下:
export function* loadApplianceSaga() {
try {
let {request, success, error} = yield take(ActionTypes.APPLIANCE.LOAD);
request.url = yield select(getResourceLink, request.resource);
const response = yield call(makeRequest, request);
if (!response.error) {
yield put({type: success, payload: response.body});
} else {
yield put({type: error, payload: response});
}
} catch (e) {
yield put({type: ActionTypes.REQUEST.CALL_ERROR, error: e});
}
}
export function* watchLoadAppliance() {
while (true) {
yield* takeEvery(ActionTypes.APPLIANCE.LOAD, loadApplianceSaga);
}
}
和根传奇:
export default function* rootSaga() {
yield [
fork(watchLoadAppliance)
]
}
我面临一个loadApplianceSaga
第一次不起作用的问题。我登录并看到它第一次只发送ActionTypes.APPLIANCE.LOAD
动作然后没有发送任何动作。但是在第二次,我可以看到发送的成功动作或失败动作。
谁能告诉我出了什么问题?提前致谢!
更新操作:
export const loadAppliances = () => {
return {
type: ActionTypes.APPLIANCE.LOAD,
request: {
resource: Resources.Appliances,
param: {
page: 0,
size: 5,
sort: 'name,desc'
},
header: {
Accept: 'application/json'
}
},
success: ActionTypes.APPLIANCE.LOAD_SUCCESS,
error: ActionTypes.APPLIANCE.LOAD_ERROR
}
};