Skip to content

Commit 3a968fd

Browse files
committed
perf: use shallowRef
1 parent 3f71a14 commit 3a968fd

File tree

12 files changed

+44
-32
lines changed

12 files changed

+44
-32
lines changed

components/table/hooks/useFilter/FilterDropdown.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import type {
1515
} from '../../interface';
1616
import FilterDropdownMenuWrapper from './FilterWrapper';
1717
import type { FilterState } from '.';
18-
import { computed, defineComponent, onBeforeUnmount, ref, watch } from 'vue';
18+
import { computed, defineComponent, onBeforeUnmount, ref, shallowRef, watch } from 'vue';
1919
import classNames from '../../../_util/classNames';
2020
import useConfigInject from '../../../_util/hooks/useConfigInject';
2121
import { useInjectSlots } from '../../context';
@@ -162,7 +162,7 @@ export default defineComponent<FilterDropdownProps<any>>({
162162

163163
const propFilteredKeys = computed(() => props.filterState?.filteredKeys);
164164

165-
const filteredKeys = ref([]);
165+
const filteredKeys = shallowRef([]);
166166

167167
const onSelectKeys = ({ selectedKeys }: { selectedKeys?: Key[] }) => {
168168
filteredKeys.value = selectedKeys;
@@ -176,7 +176,7 @@ export default defineComponent<FilterDropdownProps<any>>({
176176
{ immediate: true },
177177
);
178178

179-
const openKeys = ref([]);
179+
const openKeys = shallowRef([]);
180180

181181
const openRef = ref();
182182

components/table/hooks/useLazyKVMap.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Ref } from 'vue';
2-
import { watch, ref } from 'vue';
2+
import { watch, shallowRef } from 'vue';
33
import type { Key, GetRowKey } from '../interface';
44

55
interface MapCache<RecordType> {
@@ -11,7 +11,7 @@ export default function useLazyKVMap<RecordType>(
1111
childrenColumnNameRef: Ref<string>,
1212
getRowKeyRef: Ref<GetRowKey<RecordType>>,
1313
) {
14-
const mapCacheRef = ref<MapCache<RecordType>>({});
14+
const mapCacheRef = shallowRef<MapCache<RecordType>>({});
1515

1616
watch(
1717
[dataRef, childrenColumnNameRef, getRowKeyRef],

components/table/hooks/useSelection.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import devWarning from '../../vc-util/devWarning';
1010
import useMergedState from '../../_util/hooks/useMergedState';
1111
import useState from '../../_util/hooks/useState';
1212
import type { Ref } from 'vue';
13-
import { computed, ref, watchEffect } from 'vue';
13+
import { computed, shallowRef, watchEffect } from 'vue';
1414
import type { CheckboxProps } from '../../checkbox';
1515
import Checkbox from '../../checkbox';
1616
import Dropdown from '../../dropdown';
@@ -80,7 +80,7 @@ export default function useSelection<RecordType>(
8080
configRef: UseSelectionConfig<RecordType>,
8181
): [TransformColumns<RecordType>, Ref<Set<Key>>] {
8282
// ======================== Caches ========================
83-
const preserveRecordsRef = ref(new Map<Key, RecordType>());
83+
const preserveRecordsRef = shallowRef(new Map<Key, RecordType>());
8484
const mergedRowSelection = computed(() => {
8585
const temp = rowSelectionRef.value || {};
8686
const { checkStrictly = true } = temp;

components/vc-select/generate.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import {
4545
onMounted,
4646
provide,
4747
ref,
48+
shallowRef,
4849
watch,
4950
watchEffect,
5051
} from 'vue';
@@ -519,7 +520,7 @@ export default function generateSelector<
519520
};
520521

521522
// We need cache options here in case user update the option list
522-
const prevValueOptions = ref([]);
523+
const prevValueOptions = shallowRef([]);
523524
const setPrevValueOptions = (val: any[]) => {
524525
prevValueOptions.value = val;
525526
};

components/vc-table/Table.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
onMounted,
4040
reactive,
4141
ref,
42+
shallowRef,
4243
toRef,
4344
toRefs,
4445
watch,
@@ -250,7 +251,7 @@ export default defineComponent<TableProps<DefaultRecordType>>({
250251
return false;
251252
});
252253

253-
const innerExpandedKeys = ref([]);
254+
const innerExpandedKeys = shallowRef([]);
254255
const stop = watchEffect(() => {
255256
if (props.defaultExpandedRowKeys) {
256257
innerExpandedKeys.value = props.defaultExpandedRowKeys;

components/vc-tree-select/OptionList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { DataNode, TreeDataNode, Key } from './interface';
22
import { useInjectTreeSelectContext } from './Context';
33
import type { RefOptionListProps } from '../vc-select/OptionList';
44
import type { ScrollTo } from '../vc-virtual-list/List';
5-
import { computed, defineComponent, nextTick, ref, watch } from 'vue';
5+
import { computed, defineComponent, nextTick, ref, shallowRef, watch } from 'vue';
66
import { optionListProps } from './props';
77
import useMemo from '../_util/hooks/useMemo';
88
import type { EventDataNode } from '../tree';
@@ -88,8 +88,8 @@ export default defineComponent({
8888
};
8989

9090
// =========================== Keys ===========================
91-
const expandedKeys = ref<Key[]>(context.value.treeDefaultExpandedKeys);
92-
const searchExpandedKeys = ref<Key[]>(null);
91+
const expandedKeys = shallowRef<Key[]>(context.value.treeDefaultExpandedKeys);
92+
const searchExpandedKeys = shallowRef<Key[]>(null);
9393

9494
watch(
9595
() => props.searchValue,

components/vc-tree-select/generate.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import type { TreeSelectProps } from './props';
3333
import { treeSelectProps } from './props';
3434
import { getLabeledValue } from '../vc-select/utils/valueUtil';
3535
import omit from '../_util/omit';
36-
import { computed, defineComponent, ref, toRef, watch, watchEffect } from 'vue';
36+
import { computed, defineComponent, ref, shallowRef, toRef, watch, watchEffect } from 'vue';
3737
import { convertDataToEntities } from '../vc-tree/utils/treeUtil';
3838
import { conductCheck } from '../vc-tree/utils/conductUtil';
3939
import { warning } from '../vc-util/warning';
@@ -202,8 +202,8 @@ export default function generate(config: {
202202
return { missingRawValues, existRawValues };
203203
};
204204

205-
const rawValues = ref<RawValueType[]>([]);
206-
const rawHalfCheckedKeys = ref<RawValueType[]>([]);
205+
const rawValues = shallowRef<RawValueType[]>([]);
206+
const rawHalfCheckedKeys = shallowRef<RawValueType[]>([]);
207207

208208
watchEffect(() => {
209209
const valueHalfCheckedKeys: RawValueType[] = [];

components/vc-tree-select/hooks/useKeyValueMap.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
import type { ComputedRef, Ref } from 'vue';
2-
import { ref, watchEffect } from 'vue';
2+
import { shallowRef, watchEffect } from 'vue';
33
import type { FlattenDataNode, Key, RawValueType } from '../interface';
44

55
/**
66
* Return cached Key Value map with DataNode.
77
* Only re-calculate when `flattenOptions` changed.
88
*/
99
export default function useKeyValueMap(flattenOptions: ComputedRef<FlattenDataNode[]>) {
10-
const cacheKeyMap: Ref<Map<Key, FlattenDataNode>> = ref(new Map());
11-
const cacheValueMap: Ref<Map<RawValueType, FlattenDataNode>> = ref(new Map());
10+
const cacheKeyMap: Ref<Map<Key, FlattenDataNode>> = shallowRef(new Map());
11+
const cacheValueMap: Ref<Map<RawValueType, FlattenDataNode>> = shallowRef(new Map());
1212

1313
watchEffect(() => {
1414
const newCacheKeyMap = new Map();

components/vc-tree-select/hooks/useSelectValues.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { formatStrategyKeys } from '../utils/strategyUtil';
66
import type { DefaultValueType } from '../../vc-select/interface/generator';
77
import type { DataEntity } from '../../vc-tree/interface';
88
import type { Ref } from 'vue';
9-
import { ref, watchEffect } from 'vue';
9+
import { shallowRef, watchEffect } from 'vue';
1010

1111
interface Config {
1212
treeConduction: Ref<boolean>;
@@ -36,7 +36,7 @@ export default function useSelectValues(
3636
getLabelProp,
3737
}: Config,
3838
): Ref<LabelValueType[]> {
39-
const rawValueLabeled = ref([]);
39+
const rawValueLabeled = shallowRef([]);
4040
watchEffect(() => {
4141
let mergedRawValues = rawValues.value;
4242

components/vc-tree/MotionTreeNode.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
onBeforeUnmount,
1212
onMounted,
1313
ref,
14+
shallowRef,
1415
Transition,
1516
watch,
1617
} from 'vue';
@@ -36,7 +37,7 @@ export default defineComponent({
3637
const context = useInjectTreeContext();
3738
const motionedRef = ref(false);
3839
const transitionClass = ref('');
39-
const transitionStyle = ref({});
40+
const transitionStyle = shallowRef({});
4041
const transitionProps = computed(() => {
4142
if (props.motion) {
4243
return props.motion;

components/vc-tree/NodeList.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Handle virtual list of the TreeNodes.
33
*/
44

5-
import { computed, defineComponent, ref, watch } from 'vue';
5+
import { computed, defineComponent, ref, shallowRef, watch } from 'vue';
66
import VirtualList from '../vc-virtual-list';
77
import type { FlattenNode, DataEntity, DataNode, ScrollTo } from './interface';
88
import MotionTreeNode from './MotionTreeNode';
@@ -102,8 +102,8 @@ export default defineComponent({
102102
getIndentWidth: () => indentMeasurerRef.value.offsetWidth,
103103
});
104104
// ============================== Motion ==============================
105-
const transitionData = ref<FlattenNode[]>(props.data);
106-
const transitionRange = ref([]);
105+
const transitionData = shallowRef<FlattenNode[]>(props.data);
106+
const transitionRange = shallowRef([]);
107107
const motionType = ref<'show' | 'hide' | null>(null);
108108

109109
function onMotionEnd() {

components/vc-tree/Tree.tsx

+17-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,16 @@ import {
2323
import NodeList, { MOTION_KEY, MotionEntity } from './NodeList';
2424
import { conductCheck } from './utils/conductUtil';
2525
import DropIndicator from './DropIndicator';
26-
import { computed, defineComponent, onMounted, onUnmounted, reactive, ref, watchEffect } from 'vue';
26+
import {
27+
computed,
28+
defineComponent,
29+
onMounted,
30+
onUnmounted,
31+
reactive,
32+
ref,
33+
shallowRef,
34+
watchEffect,
35+
} from 'vue';
2736
import initDefaultProps from '../_util/props-util/initDefaultProps';
2837
import type { CheckInfo } from './props';
2938
import { treeProps } from './props';
@@ -59,12 +68,12 @@ export default defineComponent({
5968
const destroyed = ref(false);
6069
let delayedDragEnterLogic: Record<Key, number> = {};
6170
const indent = ref();
62-
const selectedKeys = ref([]);
63-
const checkedKeys = ref([]);
64-
const halfCheckedKeys = ref([]);
65-
const loadedKeys = ref([]);
66-
const loadingKeys = ref([]);
67-
const expandedKeys = ref([]);
71+
const selectedKeys = shallowRef([]);
72+
const checkedKeys = shallowRef([]);
73+
const halfCheckedKeys = shallowRef([]);
74+
const loadedKeys = shallowRef([]);
75+
const loadingKeys = shallowRef([]);
76+
const expandedKeys = shallowRef([]);
6877

6978
const dragState = reactive({
7079
dragging: false,
@@ -87,7 +96,7 @@ export default defineComponent({
8796
const treeData = computed(() => {
8897
return props.treeData !== undefined ? props.treeData : convertTreeToData(props.children);
8998
});
90-
const keyEntities = ref({});
99+
const keyEntities = shallowRef({});
91100

92101
const focused = ref(false);
93102
const activeKey = ref<Key>(null);

0 commit comments

Comments
 (0)