Skip to content

Commit 9004644

Browse files
committed
perf: table hover & stickyScroll
1 parent 797a1c6 commit 9004644

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

components/vc-table/Body/index.tsx

+6-2
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,16 @@ export default defineComponent<BodyProps<any>>({
4646
);
4747
const startRow = ref(-1);
4848
const endRow = ref(-1);
49+
let timeoutId: any;
4950
useProvideHover({
5051
startRow,
5152
endRow,
5253
onHover: (start, end) => {
53-
startRow.value = start;
54-
endRow.value = end;
54+
clearTimeout(timeoutId);
55+
timeoutId = setTimeout(() => {
56+
startRow.value = start;
57+
endRow.value = end;
58+
}, 100);
5559
},
5660
});
5761
return () => {

components/vc-table/Cell/index.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import { useInjectHover } from '../context/HoverContext';
2222
import { useInjectSticky } from '../context/StickyContext';
2323
import { warning } from '../../vc-util/warning';
2424
import type { MouseEventHandler } from '../../_util/EventInterface';
25+
import eagerComputed from '../../_util/eagerComputed';
2526

2627
/** Check if cell is in hover range */
2728
function inHoverRange(cellStartRow: number, cellRowSpan: number, startRow: number, endRow: number) {
@@ -120,7 +121,7 @@ export default defineComponent<CellProps>({
120121
(props.additionalProps?.rowspan as number)
121122
);
122123
});
123-
const hovering = computed(() => {
124+
const hovering = eagerComputed(() => {
124125
const { index } = props;
125126
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
126127
});

components/vc-table/stickyScrollBar.tsx

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
import type { Ref } from 'vue';
2-
import {
3-
watchEffect,
4-
getCurrentInstance,
5-
defineComponent,
6-
onBeforeUnmount,
7-
onMounted,
8-
ref,
9-
watch,
10-
} from 'vue';
2+
import { watchEffect, defineComponent, onBeforeUnmount, onMounted, ref, watch } from 'vue';
113
import addEventListenerWrap from '../vc-util/Dom/addEventListener';
124
import { getOffset } from '../vc-util/Dom/css';
135
import classNames from '../_util/classNames';
@@ -34,7 +26,6 @@ export default defineComponent<StickyScrollBarProps>({
3426
const bodyScrollWidth = ref(0);
3527
const bodyWidth = ref(0);
3628
const scrollBarWidth = ref(0);
37-
const instance = getCurrentInstance();
3829
watchEffect(
3930
() => {
4031
bodyScrollWidth.value = props.scrollBodySizeInfo.scrollWidth || 0;
@@ -120,7 +111,6 @@ export default defineComponent<StickyScrollBarProps>({
120111
isHiddenScrollBar: false,
121112
}));
122113
}
123-
instance.update?.();
124114
};
125115

126116
const setScrollLeft = (left: number) => {

0 commit comments

Comments
 (0)