chore: improve multiple watch source (#8253)

This commit is contained in:
neverland 2021-03-03 16:32:38 +08:00 committed by GitHub
parent 7f4651bbbf
commit 202edb24c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 20 deletions

View File

@ -503,9 +503,12 @@ export default createComponent({
); );
watch(() => props.show, init); watch(() => props.show, init);
watch([() => props.type, () => props.minDate, () => props.maxDate], () => { watch(
reset(getInitialDate(state.currentDate)); () => [props.type, props.minDate, props.maxDate],
}); () => {
reset(getInitialDate(state.currentDate));
}
);
watch( watch(
() => props.defaultDate, () => props.defaultDate,
(value) => { (value) => {

View File

@ -33,12 +33,8 @@ export default createComponent({
const { start, pause, reset, current } = useCountDown({ const { start, pause, reset, current } = useCountDown({
time: +props.time, time: +props.time,
millisecond: props.millisecond, millisecond: props.millisecond,
onChange(current) { onChange: (current) => emit('change', current),
emit('change', current); onFinish: () => emit('finish'),
},
onFinish() {
emit('finish');
},
}); });
const timeText = computed(() => parseFormat(props.format, current.value)); const timeText = computed(() => parseFormat(props.format, current.value));

View File

@ -173,7 +173,7 @@ export default createComponent({
// see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/ // see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
useEventListener('pageshow', start); useEventListener('pageshow', start);
watch([() => props.text, () => props.scrollable], start); watch(() => [props.text, props.scrollable], start);
return () => { return () => {
const { color, wrapable, background } = props; const { color, wrapable, background } = props;

View File

@ -175,7 +175,7 @@ export default createComponent({
} }
}); });
watch([() => props.show, () => props.placement], updateLocation); watch(() => [props.show, props.placement], updateLocation);
useClickAway(wrapperRef, onClickAway, { eventName: 'touchstart' }); useClickAway(wrapperRef, onClickAway, { eventName: 'touchstart' });

View File

@ -66,7 +66,7 @@ export default createComponent({
} }
}; };
watch([() => props.showPivot, () => props.pivotText], resize); watch(() => [props.showPivot, props.pivotText], resize);
onMounted(resize); onMounted(resize);
useExpose({ resize }); useExpose({ resize });

View File

@ -103,16 +103,19 @@ export default createComponent({
} }
}; };
watch([() => props.show, () => props.forbidClick], toggleClickable); watch(() => [props.show, props.forbidClick], toggleClickable);
watch([() => props.show, () => props.duration], () => { watch(
clearTimer(); () => [props.show, props.duration],
if (props.show && props.duration > 0) { () => {
timer = setTimeout(() => { clearTimer();
updateShow(false); if (props.show && props.duration > 0) {
}, props.duration); timer = setTimeout(() => {
updateShow(false);
}, props.duration);
}
} }
}); );
onMounted(toggleClickable); onMounted(toggleClickable);
onUnmounted(toggleClickable); onUnmounted(toggleClickable);