Skip to content

Commit

Permalink
fix(table): params change awaly reload fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Jul 19, 2023
1 parent 2ab5562 commit b147a16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
7 changes: 6 additions & 1 deletion packages/table/src/Store/Provide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,12 @@ function useContainer(props: UseContainerProps = {}) {
console.warn(error);
}
}
}, [props.columnsState, defaultColumnKeyMap, setColumnsMap]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [
props.columnsState?.persistenceKey,
props.columnsState?.persistenceType,
defaultColumnKeyMap,
]);

noteOnce(
!props.columnsStateMap,
Expand Down
22 changes: 14 additions & 8 deletions packages/table/src/useFetchData.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,6 @@ const useFetchData = <DataSource extends RequestData<any>>(
pageSize,
}
: undefined;

const {
data = [],
success,
Expand Down Expand Up @@ -238,7 +237,6 @@ const useFetchData = <DataSource extends RequestData<any>>(
if (pollingSetTimeRef.current) {
clearTimeout(pollingSetTimeRef.current);
}
abortRef.current?.abort();
if (!getData) {
return;
}
Expand Down Expand Up @@ -290,6 +288,15 @@ const useFetchData = <DataSource extends RequestData<any>>(
}
}, debounceTime || 30);

/**
* 取消请求
*/
const abortFetch = () => {
abortRef.current?.abort();
fetchListDebounce.cancel();
requestFinally();
};

// 如果轮询结束了,直接销毁定时器
useEffect(() => {
if (!polling) {
Expand Down Expand Up @@ -341,7 +348,7 @@ const useFetchData = <DataSource extends RequestData<any>>(
tableDataList &&
tableDataList.length <= pageSize
) {
abortRef.current?.abort();
abortFetch();
fetchListDebounce.run(false);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
Expand All @@ -352,7 +359,7 @@ const useFetchData = <DataSource extends RequestData<any>>(
if (!prePageSize) {
return;
}
abortRef.current?.abort();
abortFetch();
fetchListDebounce.run(false);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [pageInfo?.pageSize]);
Expand All @@ -363,15 +370,15 @@ const useFetchData = <DataSource extends RequestData<any>>(
* 最后,检查是否有正在进行的请求,如果有,则中止它。
*/
useDeepCompareEffect(() => {
abortRef.current?.abort();
abortFetch();
fetchListDebounce.run(false);
if (!manual) {
// 如果 manual 标志未设置,则将 manualRequestRef 设置为 false。
// 用于跟踪当前的请求是否是手动发起的。
manualRequestRef.current = false;
}
return () => {
abortRef.current?.abort();
abortFetch();
};
}, [...effects, manual]);

Expand Down Expand Up @@ -402,8 +409,7 @@ const useFetchData = <DataSource extends RequestData<any>>(
* @returns {Promise<boolean>} - 数据重新加载完成后解决为 true 的 Promise。
*/
reload: async () => {
abortRef.current?.abort();
fetchListDebounce.cancel();
abortFetch();
return fetchListDebounce.run(false);
},
/**
Expand Down

0 comments on commit b147a16

Please sign in to comment.