测试条件是,我们一次一个接一个地调用3-4个API,并且API的加载需要一些时间。在此期间,如果我们按下back按钮或任何其他UI组件,它将在调用完所有API之后进行响应。所以我想取消点击按钮时的API。
export function* getData(api, action) {
const { location } = action;
// make the call to the api
const response = yield call(api.daily, location);
if (response.status === 200) {
// do data conversion here if needed
yield put(LocationActions.Success(response.data));
} else {
const error = errorType(response);
yield put(Actions.Failure(error));
}
}发布于 2019-05-22 17:51:39
lodash库应该可以做到这一点:
// create debounce
debouncedThing = _.debounce(thing, 1000);
// execute debounced api call
this.debouncedThing();
// onpress button
debouncedThing.cancel()有关this answer的更多详细信息
有关安装和使用的更多信息,请参阅lodash library。
https://stackoverflow.com/questions/56253423
复制相似问题