perf: use shallowRef

pull/4773/head
tangjinzhou 3 years ago
parent 3f71a14874
commit 3a968fdd33

@ -15,7 +15,7 @@ import type {
} from '../../interface'; } from '../../interface';
import FilterDropdownMenuWrapper from './FilterWrapper'; import FilterDropdownMenuWrapper from './FilterWrapper';
import type { FilterState } from '.'; import type { FilterState } from '.';
import { computed, defineComponent, onBeforeUnmount, ref, watch } from 'vue'; import { computed, defineComponent, onBeforeUnmount, ref, shallowRef, watch } from 'vue';
import classNames from '../../../_util/classNames'; import classNames from '../../../_util/classNames';
import useConfigInject from '../../../_util/hooks/useConfigInject'; import useConfigInject from '../../../_util/hooks/useConfigInject';
import { useInjectSlots } from '../../context'; import { useInjectSlots } from '../../context';
@ -162,7 +162,7 @@ export default defineComponent<FilterDropdownProps<any>>({
const propFilteredKeys = computed(() => props.filterState?.filteredKeys); const propFilteredKeys = computed(() => props.filterState?.filteredKeys);
const filteredKeys = ref([]); const filteredKeys = shallowRef([]);
const onSelectKeys = ({ selectedKeys }: { selectedKeys?: Key[] }) => { const onSelectKeys = ({ selectedKeys }: { selectedKeys?: Key[] }) => {
filteredKeys.value = selectedKeys; filteredKeys.value = selectedKeys;
@ -176,7 +176,7 @@ export default defineComponent<FilterDropdownProps<any>>({
{ immediate: true }, { immediate: true },
); );
const openKeys = ref([]); const openKeys = shallowRef([]);
const openRef = ref(); const openRef = ref();

@ -1,5 +1,5 @@
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { watch, ref } from 'vue'; import { watch, shallowRef } from 'vue';
import type { Key, GetRowKey } from '../interface'; import type { Key, GetRowKey } from '../interface';
interface MapCache<RecordType> { interface MapCache<RecordType> {
@ -11,7 +11,7 @@ export default function useLazyKVMap<RecordType>(
childrenColumnNameRef: Ref<string>, childrenColumnNameRef: Ref<string>,
getRowKeyRef: Ref<GetRowKey<RecordType>>, getRowKeyRef: Ref<GetRowKey<RecordType>>,
) { ) {
const mapCacheRef = ref<MapCache<RecordType>>({}); const mapCacheRef = shallowRef<MapCache<RecordType>>({});
watch( watch(
[dataRef, childrenColumnNameRef, getRowKeyRef], [dataRef, childrenColumnNameRef, getRowKeyRef],

@ -10,7 +10,7 @@ import devWarning from '../../vc-util/devWarning';
import useMergedState from '../../_util/hooks/useMergedState'; import useMergedState from '../../_util/hooks/useMergedState';
import useState from '../../_util/hooks/useState'; import useState from '../../_util/hooks/useState';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { computed, ref, watchEffect } from 'vue'; import { computed, shallowRef, watchEffect } from 'vue';
import type { CheckboxProps } from '../../checkbox'; import type { CheckboxProps } from '../../checkbox';
import Checkbox from '../../checkbox'; import Checkbox from '../../checkbox';
import Dropdown from '../../dropdown'; import Dropdown from '../../dropdown';
@ -80,7 +80,7 @@ export default function useSelection<RecordType>(
configRef: UseSelectionConfig<RecordType>, configRef: UseSelectionConfig<RecordType>,
): [TransformColumns<RecordType>, Ref<Set<Key>>] { ): [TransformColumns<RecordType>, Ref<Set<Key>>] {
// ======================== Caches ======================== // ======================== Caches ========================
const preserveRecordsRef = ref(new Map<Key, RecordType>()); const preserveRecordsRef = shallowRef(new Map<Key, RecordType>());
const mergedRowSelection = computed(() => { const mergedRowSelection = computed(() => {
const temp = rowSelectionRef.value || {}; const temp = rowSelectionRef.value || {};
const { checkStrictly = true } = temp; const { checkStrictly = true } = temp;

@ -45,6 +45,7 @@ import {
onMounted, onMounted,
provide, provide,
ref, ref,
shallowRef,
watch, watch,
watchEffect, watchEffect,
} from 'vue'; } from 'vue';
@ -519,7 +520,7 @@ export default function generateSelector<
}; };
// We need cache options here in case user update the option list // We need cache options here in case user update the option list
const prevValueOptions = ref([]); const prevValueOptions = shallowRef([]);
const setPrevValueOptions = (val: any[]) => { const setPrevValueOptions = (val: any[]) => {
prevValueOptions.value = val; prevValueOptions.value = val;
}; };

@ -39,6 +39,7 @@ import {
onMounted, onMounted,
reactive, reactive,
ref, ref,
shallowRef,
toRef, toRef,
toRefs, toRefs,
watch, watch,
@ -250,7 +251,7 @@ export default defineComponent<TableProps<DefaultRecordType>>({
return false; return false;
}); });
const innerExpandedKeys = ref([]); const innerExpandedKeys = shallowRef([]);
const stop = watchEffect(() => { const stop = watchEffect(() => {
if (props.defaultExpandedRowKeys) { if (props.defaultExpandedRowKeys) {
innerExpandedKeys.value = props.defaultExpandedRowKeys; innerExpandedKeys.value = props.defaultExpandedRowKeys;

@ -2,7 +2,7 @@ import type { DataNode, TreeDataNode, Key } from './interface';
import { useInjectTreeSelectContext } from './Context'; import { useInjectTreeSelectContext } from './Context';
import type { RefOptionListProps } from '../vc-select/OptionList'; import type { RefOptionListProps } from '../vc-select/OptionList';
import type { ScrollTo } from '../vc-virtual-list/List'; import type { ScrollTo } from '../vc-virtual-list/List';
import { computed, defineComponent, nextTick, ref, watch } from 'vue'; import { computed, defineComponent, nextTick, ref, shallowRef, watch } from 'vue';
import { optionListProps } from './props'; import { optionListProps } from './props';
import useMemo from '../_util/hooks/useMemo'; import useMemo from '../_util/hooks/useMemo';
import type { EventDataNode } from '../tree'; import type { EventDataNode } from '../tree';
@ -88,8 +88,8 @@ export default defineComponent({
}; };
// =========================== Keys =========================== // =========================== Keys ===========================
const expandedKeys = ref<Key[]>(context.value.treeDefaultExpandedKeys); const expandedKeys = shallowRef<Key[]>(context.value.treeDefaultExpandedKeys);
const searchExpandedKeys = ref<Key[]>(null); const searchExpandedKeys = shallowRef<Key[]>(null);
watch( watch(
() => props.searchValue, () => props.searchValue,

@ -33,7 +33,7 @@ import type { TreeSelectProps } from './props';
import { treeSelectProps } from './props'; import { treeSelectProps } from './props';
import { getLabeledValue } from '../vc-select/utils/valueUtil'; import { getLabeledValue } from '../vc-select/utils/valueUtil';
import omit from '../_util/omit'; import omit from '../_util/omit';
import { computed, defineComponent, ref, toRef, watch, watchEffect } from 'vue'; import { computed, defineComponent, ref, shallowRef, toRef, watch, watchEffect } from 'vue';
import { convertDataToEntities } from '../vc-tree/utils/treeUtil'; import { convertDataToEntities } from '../vc-tree/utils/treeUtil';
import { conductCheck } from '../vc-tree/utils/conductUtil'; import { conductCheck } from '../vc-tree/utils/conductUtil';
import { warning } from '../vc-util/warning'; import { warning } from '../vc-util/warning';
@ -202,8 +202,8 @@ export default function generate(config: {
return { missingRawValues, existRawValues }; return { missingRawValues, existRawValues };
}; };
const rawValues = ref<RawValueType[]>([]); const rawValues = shallowRef<RawValueType[]>([]);
const rawHalfCheckedKeys = ref<RawValueType[]>([]); const rawHalfCheckedKeys = shallowRef<RawValueType[]>([]);
watchEffect(() => { watchEffect(() => {
const valueHalfCheckedKeys: RawValueType[] = []; const valueHalfCheckedKeys: RawValueType[] = [];

@ -1,5 +1,5 @@
import type { ComputedRef, Ref } from 'vue'; import type { ComputedRef, Ref } from 'vue';
import { ref, watchEffect } from 'vue'; import { shallowRef, watchEffect } from 'vue';
import type { FlattenDataNode, Key, RawValueType } from '../interface'; import type { FlattenDataNode, Key, RawValueType } from '../interface';
/** /**
@ -7,8 +7,8 @@ import type { FlattenDataNode, Key, RawValueType } from '../interface';
* Only re-calculate when `flattenOptions` changed. * Only re-calculate when `flattenOptions` changed.
*/ */
export default function useKeyValueMap(flattenOptions: ComputedRef<FlattenDataNode[]>) { export default function useKeyValueMap(flattenOptions: ComputedRef<FlattenDataNode[]>) {
const cacheKeyMap: Ref<Map<Key, FlattenDataNode>> = ref(new Map()); const cacheKeyMap: Ref<Map<Key, FlattenDataNode>> = shallowRef(new Map());
const cacheValueMap: Ref<Map<RawValueType, FlattenDataNode>> = ref(new Map()); const cacheValueMap: Ref<Map<RawValueType, FlattenDataNode>> = shallowRef(new Map());
watchEffect(() => { watchEffect(() => {
const newCacheKeyMap = new Map(); const newCacheKeyMap = new Map();

@ -6,7 +6,7 @@ import { formatStrategyKeys } from '../utils/strategyUtil';
import type { DefaultValueType } from '../../vc-select/interface/generator'; import type { DefaultValueType } from '../../vc-select/interface/generator';
import type { DataEntity } from '../../vc-tree/interface'; import type { DataEntity } from '../../vc-tree/interface';
import type { Ref } from 'vue'; import type { Ref } from 'vue';
import { ref, watchEffect } from 'vue'; import { shallowRef, watchEffect } from 'vue';
interface Config { interface Config {
treeConduction: Ref<boolean>; treeConduction: Ref<boolean>;
@ -36,7 +36,7 @@ export default function useSelectValues(
getLabelProp, getLabelProp,
}: Config, }: Config,
): Ref<LabelValueType[]> { ): Ref<LabelValueType[]> {
const rawValueLabeled = ref([]); const rawValueLabeled = shallowRef([]);
watchEffect(() => { watchEffect(() => {
let mergedRawValues = rawValues.value; let mergedRawValues = rawValues.value;

@ -11,6 +11,7 @@ import {
onBeforeUnmount, onBeforeUnmount,
onMounted, onMounted,
ref, ref,
shallowRef,
Transition, Transition,
watch, watch,
} from 'vue'; } from 'vue';
@ -36,7 +37,7 @@ export default defineComponent({
const context = useInjectTreeContext(); const context = useInjectTreeContext();
const motionedRef = ref(false); const motionedRef = ref(false);
const transitionClass = ref(''); const transitionClass = ref('');
const transitionStyle = ref({}); const transitionStyle = shallowRef({});
const transitionProps = computed(() => { const transitionProps = computed(() => {
if (props.motion) { if (props.motion) {
return props.motion; return props.motion;

@ -2,7 +2,7 @@
* Handle virtual list of the TreeNodes. * Handle virtual list of the TreeNodes.
*/ */
import { computed, defineComponent, ref, watch } from 'vue'; import { computed, defineComponent, ref, shallowRef, watch } from 'vue';
import VirtualList from '../vc-virtual-list'; import VirtualList from '../vc-virtual-list';
import type { FlattenNode, DataEntity, DataNode, ScrollTo } from './interface'; import type { FlattenNode, DataEntity, DataNode, ScrollTo } from './interface';
import MotionTreeNode from './MotionTreeNode'; import MotionTreeNode from './MotionTreeNode';
@ -102,8 +102,8 @@ export default defineComponent({
getIndentWidth: () => indentMeasurerRef.value.offsetWidth, getIndentWidth: () => indentMeasurerRef.value.offsetWidth,
}); });
// ============================== Motion ============================== // ============================== Motion ==============================
const transitionData = ref<FlattenNode[]>(props.data); const transitionData = shallowRef<FlattenNode[]>(props.data);
const transitionRange = ref([]); const transitionRange = shallowRef([]);
const motionType = ref<'show' | 'hide' | null>(null); const motionType = ref<'show' | 'hide' | null>(null);
function onMotionEnd() { function onMotionEnd() {

@ -23,7 +23,16 @@ import {
import NodeList, { MOTION_KEY, MotionEntity } from './NodeList'; import NodeList, { MOTION_KEY, MotionEntity } from './NodeList';
import { conductCheck } from './utils/conductUtil'; import { conductCheck } from './utils/conductUtil';
import DropIndicator from './DropIndicator'; import DropIndicator from './DropIndicator';
import { computed, defineComponent, onMounted, onUnmounted, reactive, ref, watchEffect } from 'vue'; import {
computed,
defineComponent,
onMounted,
onUnmounted,
reactive,
ref,
shallowRef,
watchEffect,
} from 'vue';
import initDefaultProps from '../_util/props-util/initDefaultProps'; import initDefaultProps from '../_util/props-util/initDefaultProps';
import type { CheckInfo } from './props'; import type { CheckInfo } from './props';
import { treeProps } from './props'; import { treeProps } from './props';
@ -59,12 +68,12 @@ export default defineComponent({
const destroyed = ref(false); const destroyed = ref(false);
let delayedDragEnterLogic: Record<Key, number> = {}; let delayedDragEnterLogic: Record<Key, number> = {};
const indent = ref(); const indent = ref();
const selectedKeys = ref([]); const selectedKeys = shallowRef([]);
const checkedKeys = ref([]); const checkedKeys = shallowRef([]);
const halfCheckedKeys = ref([]); const halfCheckedKeys = shallowRef([]);
const loadedKeys = ref([]); const loadedKeys = shallowRef([]);
const loadingKeys = ref([]); const loadingKeys = shallowRef([]);
const expandedKeys = ref([]); const expandedKeys = shallowRef([]);
const dragState = reactive({ const dragState = reactive({
dragging: false, dragging: false,
@ -87,7 +96,7 @@ export default defineComponent({
const treeData = computed(() => { const treeData = computed(() => {
return props.treeData !== undefined ? props.treeData : convertTreeToData(props.children); return props.treeData !== undefined ? props.treeData : convertTreeToData(props.children);
}); });
const keyEntities = ref({}); const keyEntities = shallowRef({});
const focused = ref(false); const focused = ref(false);
const activeKey = ref<Key>(null); const activeKey = ref<Key>(null);

Loading…
Cancel
Save