Skip to content

Commit

Permalink
perf: table hover & stickyScroll
Browse files Browse the repository at this point in the history
  • Loading branch information
tangjinzhou committed Mar 30, 2022
1 parent 797a1c6 commit 9004644
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
8 changes: 6 additions & 2 deletions components/vc-table/Body/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,16 @@ export default defineComponent<BodyProps<any>>({
);
const startRow = ref(-1);
const endRow = ref(-1);
let timeoutId: any;
useProvideHover({
startRow,
endRow,
onHover: (start, end) => {
startRow.value = start;
endRow.value = end;
clearTimeout(timeoutId);
timeoutId = setTimeout(() => {
startRow.value = start;
endRow.value = end;
}, 100);
},
});
return () => {
Expand Down
3 changes: 2 additions & 1 deletion components/vc-table/Cell/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import { useInjectHover } from '../context/HoverContext';
import { useInjectSticky } from '../context/StickyContext';
import { warning } from '../../vc-util/warning';
import type { MouseEventHandler } from '../../_util/EventInterface';
import eagerComputed from '../../_util/eagerComputed';

/** Check if cell is in hover range */
function inHoverRange(cellStartRow: number, cellRowSpan: number, startRow: number, endRow: number) {
Expand Down Expand Up @@ -120,7 +121,7 @@ export default defineComponent<CellProps>({
(props.additionalProps?.rowspan as number)
);
});
const hovering = computed(() => {
const hovering = eagerComputed(() => {
const { index } = props;
return inHoverRange(index, rowSpan.value || 1, startRow.value, endRow.value);
});
Expand Down
12 changes: 1 addition & 11 deletions components/vc-table/stickyScrollBar.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import type { Ref } from 'vue';
import {
watchEffect,
getCurrentInstance,
defineComponent,
onBeforeUnmount,
onMounted,
ref,
watch,
} from 'vue';
import { watchEffect, defineComponent, onBeforeUnmount, onMounted, ref, watch } from 'vue';
import addEventListenerWrap from '../vc-util/Dom/addEventListener';
import { getOffset } from '../vc-util/Dom/css';
import classNames from '../_util/classNames';
Expand All @@ -34,7 +26,6 @@ export default defineComponent<StickyScrollBarProps>({
const bodyScrollWidth = ref(0);
const bodyWidth = ref(0);
const scrollBarWidth = ref(0);
const instance = getCurrentInstance();
watchEffect(
() => {
bodyScrollWidth.value = props.scrollBodySizeInfo.scrollWidth || 0;
Expand Down Expand Up @@ -120,7 +111,6 @@ export default defineComponent<StickyScrollBarProps>({
isHiddenScrollBar: false,
}));
}
instance.update?.();
};

const setScrollLeft = (left: number) => {
Expand Down

0 comments on commit 9004644

Please sign in to comment.