|
1 | 1 | import type { VNode, ExtractPropTypes, PropType } from 'vue'; |
2 | | -import { cloneVNode, isVNode, defineComponent, shallowRef, watch } from 'vue'; |
3 | | -import debounce from 'lodash-es/debounce'; |
| 2 | +import { onBeforeUnmount, cloneVNode, isVNode, defineComponent, shallowRef, watch } from 'vue'; |
| 3 | +import { debounce } from 'throttle-debounce'; |
4 | 4 | import PropTypes from '../_util/vue-types'; |
5 | 5 | import { filterEmpty, getPropsSlot } from '../_util/props-util'; |
6 | 6 | import initDefaultProps from '../_util/props-util/initDefaultProps'; |
@@ -44,37 +44,25 @@ export default defineComponent({ |
44 | 44 | setup(props, { attrs, slots }) { |
45 | 45 | const { prefixCls, size, direction } = useConfigInject('spin', props); |
46 | 46 | const [wrapSSR, hashId] = useStyle(prefixCls); |
47 | | - const sSpinning = shallowRef(props.spinning && shouldDelay(props.spinning, props.delay)); |
| 47 | + const sSpinning = shallowRef(props.spinning && !shouldDelay(props.spinning, props.delay)); |
48 | 48 | let updateSpinning: any; |
49 | | - function originalUpdateSpinning() { |
50 | | - if (sSpinning.value !== props.spinning) { |
51 | | - sSpinning.value = props.spinning; |
52 | | - } |
53 | | - } |
54 | | - function cancelExistingSpin() { |
55 | | - if (updateSpinning && updateSpinning.cancel) { |
56 | | - updateSpinning.cancel(); |
57 | | - } |
58 | | - } |
59 | | - function debouncifyUpdateSpinning() { |
60 | | - const { delay } = props; |
61 | | - if (delay) { |
62 | | - cancelExistingSpin(); |
63 | | - updateSpinning = debounce(originalUpdateSpinning, delay); |
64 | | - } else { |
65 | | - updateSpinning = originalUpdateSpinning; |
66 | | - } |
67 | | - } |
68 | 49 | watch( |
69 | | - () => [props.spinning, props.delay], |
| 50 | + [() => props.spinning, () => props.delay], |
70 | 51 | () => { |
71 | | - debouncifyUpdateSpinning(); |
| 52 | + updateSpinning?.cancel(); |
| 53 | + updateSpinning = debounce(props.delay, () => { |
| 54 | + sSpinning.value = props.spinning; |
| 55 | + }); |
72 | 56 | updateSpinning?.(); |
73 | 57 | }, |
74 | 58 | { |
75 | 59 | immediate: true, |
| 60 | + flush: 'post', |
76 | 61 | }, |
77 | 62 | ); |
| 63 | + onBeforeUnmount(() => { |
| 64 | + updateSpinning?.cancel(); |
| 65 | + }); |
78 | 66 | return () => { |
79 | 67 | const { class: cls, ...divProps } = attrs; |
80 | 68 | const { tip = slots.tip?.() } = props; |
|
0 commit comments