From 202edb24c7ffae54c4747d7212604e39869a8cd4 Mon Sep 17 00:00:00 2001 From: neverland Date: Wed, 3 Mar 2021 16:32:38 +0800 Subject: [PATCH] chore: improve multiple watch source (#8253) --- src/calendar/index.tsx | 9 ++++++--- src/count-down/index.tsx | 8 ++------ src/notice-bar/index.tsx | 2 +- src/popover/index.tsx | 2 +- src/progress/index.tsx | 2 +- src/toast/Toast.tsx | 19 +++++++++++-------- 6 files changed, 22 insertions(+), 20 deletions(-) diff --git a/src/calendar/index.tsx b/src/calendar/index.tsx index 0089b7e9a..40e55c230 100644 --- a/src/calendar/index.tsx +++ b/src/calendar/index.tsx @@ -503,9 +503,12 @@ export default createComponent({ ); watch(() => props.show, init); - watch([() => props.type, () => props.minDate, () => props.maxDate], () => { - reset(getInitialDate(state.currentDate)); - }); + watch( + () => [props.type, props.minDate, props.maxDate], + () => { + reset(getInitialDate(state.currentDate)); + } + ); watch( () => props.defaultDate, (value) => { diff --git a/src/count-down/index.tsx b/src/count-down/index.tsx index c36e315d2..017a59612 100644 --- a/src/count-down/index.tsx +++ b/src/count-down/index.tsx @@ -33,12 +33,8 @@ export default createComponent({ const { start, pause, reset, current } = useCountDown({ time: +props.time, millisecond: props.millisecond, - onChange(current) { - emit('change', current); - }, - onFinish() { - emit('finish'); - }, + onChange: (current) => emit('change', current), + onFinish: () => emit('finish'), }); const timeText = computed(() => parseFormat(props.format, current.value)); diff --git a/src/notice-bar/index.tsx b/src/notice-bar/index.tsx index 7bb21c8cb..88f353b76 100644 --- a/src/notice-bar/index.tsx +++ b/src/notice-bar/index.tsx @@ -173,7 +173,7 @@ export default createComponent({ // see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/ useEventListener('pageshow', start); - watch([() => props.text, () => props.scrollable], start); + watch(() => [props.text, props.scrollable], start); return () => { const { color, wrapable, background } = props; diff --git a/src/popover/index.tsx b/src/popover/index.tsx index 0e1a7b275..4ca2dd947 100644 --- a/src/popover/index.tsx +++ b/src/popover/index.tsx @@ -175,7 +175,7 @@ export default createComponent({ } }); - watch([() => props.show, () => props.placement], updateLocation); + watch(() => [props.show, props.placement], updateLocation); useClickAway(wrapperRef, onClickAway, { eventName: 'touchstart' }); diff --git a/src/progress/index.tsx b/src/progress/index.tsx index f953f5dc8..4bb54b15c 100644 --- a/src/progress/index.tsx +++ b/src/progress/index.tsx @@ -66,7 +66,7 @@ export default createComponent({ } }; - watch([() => props.showPivot, () => props.pivotText], resize); + watch(() => [props.showPivot, props.pivotText], resize); onMounted(resize); useExpose({ resize }); diff --git a/src/toast/Toast.tsx b/src/toast/Toast.tsx index 20a5d30de..5e7d12296 100644 --- a/src/toast/Toast.tsx +++ b/src/toast/Toast.tsx @@ -103,16 +103,19 @@ export default createComponent({ } }; - watch([() => props.show, () => props.forbidClick], toggleClickable); + watch(() => [props.show, props.forbidClick], toggleClickable); - watch([() => props.show, () => props.duration], () => { - clearTimer(); - if (props.show && props.duration > 0) { - timer = setTimeout(() => { - updateShow(false); - }, props.duration); + watch( + () => [props.show, props.duration], + () => { + clearTimer(); + if (props.show && props.duration > 0) { + timer = setTimeout(() => { + updateShow(false); + }, props.duration); + } } - }); + ); onMounted(toggleClickable); onUnmounted(toggleClickable);