refactor(transition): no longer throw error in wrong status (#4003)

fix #3993
This commit is contained in:
rex 2021-01-26 16:08:03 +08:00 committed by GitHub
parent f7c90a1761
commit 3b015fe1a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -42,6 +42,7 @@ export function transition(showDefaultValue: boolean) {
if (value === old) { if (value === old) {
return; return;
} }
value ? this.enter() : this.leave(); value ? this.enter() : this.leave();
}, },
@ -54,7 +55,10 @@ export function transition(showDefaultValue: boolean) {
this.$emit('before-enter'); this.$emit('before-enter');
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.checkStatus('enter'); if (this.status !== 'enter') {
return;
}
this.$emit('enter'); this.$emit('enter');
this.setData({ this.setData({
@ -65,9 +69,11 @@ export function transition(showDefaultValue: boolean) {
}); });
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.checkStatus('enter'); if (this.status !== 'enter') {
this.transitionEnded = false; return;
}
this.transitionEnded = false;
this.setData({ classes: classNames['enter-to'] }); this.setData({ classes: classNames['enter-to'] });
}); });
}); });
@ -86,7 +92,10 @@ export function transition(showDefaultValue: boolean) {
this.$emit('before-leave'); this.$emit('before-leave');
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.checkStatus('leave'); if (this.status !== 'leave') {
return;
}
this.$emit('leave'); this.$emit('leave');
this.setData({ this.setData({
@ -95,7 +104,10 @@ export function transition(showDefaultValue: boolean) {
}); });
requestAnimationFrame(() => { requestAnimationFrame(() => {
this.checkStatus('leave'); if (this.status !== 'leave') {
return;
}
this.transitionEnded = false; this.transitionEnded = false;
setTimeout(() => this.onTransitionEnd(), currentDuration); setTimeout(() => this.onTransitionEnd(), currentDuration);
@ -104,12 +116,6 @@ export function transition(showDefaultValue: boolean) {
}); });
}, },
checkStatus(status: 'enter' | 'leave') {
if (status !== this.status) {
throw new Error(`incongruent status: ${status}`);
}
},
onTransitionEnd() { onTransitionEnd() {
if (this.transitionEnded) { if (this.transitionEnded) {
return; return;