Skip to content

Commit 3e46f27

Browse files
committed
perf: shallowRef instead ref
1 parent 7198479 commit 3e46f27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+342
-284
lines changed

components/_util/ActionButton.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { ExtractPropTypes, PropType } from 'vue';
2-
import { onMounted, ref, defineComponent, onBeforeUnmount } from 'vue';
2+
import { shallowRef, onMounted, defineComponent, onBeforeUnmount } from 'vue';
33
import Button from '../button';
44
import type { ButtonProps } from '../button';
55
import type { LegacyButtonType } from '../button/buttonTypes';
@@ -32,9 +32,9 @@ export default defineComponent({
3232
name: 'ActionButton',
3333
props: actionButtonProps,
3434
setup(props, { slots }) {
35-
const clickedRef = ref<boolean>(false);
36-
const buttonRef = ref();
37-
const loading = ref(false);
35+
const clickedRef = shallowRef<boolean>(false);
36+
const buttonRef = shallowRef();
37+
const loading = shallowRef(false);
3838
let timeoutId: any;
3939
const isDestroyed = useDestroyed();
4040
onMounted(() => {

components/_util/BaseInput.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { defineComponent, ref, withDirectives } from 'vue';
1+
import { defineComponent, shallowRef, withDirectives } from 'vue';
22
import antInput from './antInputDirective';
33
import PropTypes from './vue-types';
44
const BaseInput = defineComponent({
@@ -8,7 +8,7 @@ const BaseInput = defineComponent({
88
},
99
emits: ['change', 'input'],
1010
setup(_p, { emit }) {
11-
const inputRef = ref(null);
11+
const inputRef = shallowRef(null);
1212
const handleChange = (e: Event) => {
1313
const { composing } = e.target as any;
1414
if ((e as any).isComposing || composing) {

components/_util/PortalWrapper.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import setStyle from './setStyle';
44
import Portal from './Portal';
55
import {
66
defineComponent,
7-
ref,
7+
shallowRef,
88
watch,
99
onMounted,
1010
onBeforeUnmount,
@@ -60,9 +60,9 @@ export default defineComponent({
6060
},
6161

6262
setup(props, { slots }) {
63-
const container = ref<HTMLElement>();
64-
const componentRef = ref();
65-
const rafId = ref<number>();
63+
const container = shallowRef<HTMLElement>();
64+
const componentRef = shallowRef();
65+
const rafId = shallowRef<number>();
6666
const scrollLocker = new ScrollLocker({
6767
container: getParent(props.getContainer) as HTMLElement,
6868
});

components/_util/hooks/_vueuse/useElementSize.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ref, watch } from 'vue';
1+
import { shallowRef, watch } from 'vue';
22
import type { MaybeComputedElementRef } from './unrefElement';
33
import type { UseResizeObserverOptions } from './useResizeObserver';
44
import { useResizeObserver } from './useResizeObserver';
@@ -23,8 +23,8 @@ export function useElementSize(
2323
options: UseResizeObserverOptions = {},
2424
) {
2525
const { box = 'content-box' } = options;
26-
const width = ref(initialSize.width);
27-
const height = ref(initialSize.height);
26+
const width = shallowRef(initialSize.width);
27+
const height = shallowRef(initialSize.height);
2828

2929
useResizeObserver(
3030
target,

components/_util/hooks/_vueuse/useSupported.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { tryOnMounted } from './tryOnMounted';
2-
import type { Ref } from 'vue';
3-
import { ref } from 'vue';
2+
import { shallowRef } from 'vue';
43

54
export function useSupported(callback: () => unknown, sync = false) {
6-
const isSupported = ref() as Ref<boolean>;
5+
const isSupported = shallowRef<boolean>();
76

87
const update = () => (isSupported.value = Boolean(callback()));
98

components/_util/hooks/useBreakpoint.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import type { Ref } from 'vue';
2-
import { onMounted, onUnmounted, ref } from 'vue';
2+
import { onMounted, onUnmounted, shallowRef } from 'vue';
33
import type { ScreenMap } from '../../_util/responsiveObserve';
44
import useResponsiveObserve from '../../_util/responsiveObserve';
55

66
function useBreakpoint(): Ref<ScreenMap> {
7-
const screens = ref<ScreenMap>({});
7+
const screens = shallowRef<ScreenMap>({});
88
let token = null;
99
const responsiveObserve = useResponsiveObserve();
1010

components/_util/hooks/useDestroyed.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { onBeforeUnmount, ref } from 'vue';
1+
import { onBeforeUnmount, shallowRef } from 'vue';
22

33
const useDestroyed = () => {
4-
const destroyed = ref(false);
4+
const destroyed = shallowRef(false);
55
onBeforeUnmount(() => {
66
destroyed.value = true;
77
});

components/_util/hooks/useFlexGapSupport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { onMounted, ref } from 'vue';
1+
import { onMounted, shallowRef } from 'vue';
22
import { detectFlexGapSupported } from '../styleChecker';
33

44
export default () => {
5-
const flexible = ref(false);
5+
const flexible = shallowRef(false);
66
onMounted(() => {
77
flexible.value = detectFlexGapSupported();
88
});

components/_util/hooks/useLayoutState.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { Ref } from 'vue';
2-
import { onBeforeUnmount, ref } from 'vue';
2+
import { onBeforeUnmount, shallowRef } from 'vue';
33
import raf from '../raf';
44

55
export type Updater<State> = (prev: State) => State;
@@ -9,11 +9,11 @@ export type Updater<State> = (prev: State) => State;
99
export function useLayoutState<State>(
1010
defaultState: State,
1111
): [Ref<State>, (updater: Updater<State>) => void] {
12-
const stateRef = ref(defaultState);
12+
const stateRef = shallowRef(defaultState);
1313
let tempState = stateRef.value;
1414

1515
let updateBatchRef = [];
16-
const rafRef = ref();
16+
const rafRef = shallowRef();
1717
function setFrameState(updater: Updater<State>) {
1818
raf.cancel(rafRef.value);
1919
updateBatchRef.push(updater);

components/_util/transButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { CSSProperties } from 'vue';
2-
import { defineComponent, ref, onMounted } from 'vue';
2+
import { defineComponent, shallowRef, onMounted } from 'vue';
33
/**
44
* Wrap of sub component which need use as Button capacity (like Icon component).
55
* This helps accessibility reader to tread as a interactive button to operation.
@@ -25,7 +25,7 @@ const TransButton = defineComponent({
2525
autofocus: { type: Boolean, default: undefined },
2626
},
2727
setup(props, { slots, emit, attrs, expose }) {
28-
const domRef = ref();
28+
const domRef = shallowRef();
2929
const onKeyDown = (event: KeyboardEvent) => {
3030
const { keyCode } = event;
3131
if (keyCode === KeyCode.ENTER) {

0 commit comments

Comments
 (0)