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) {
return;
}
value ? this.enter() : this.leave();
},
@ -54,7 +55,10 @@ export function transition(showDefaultValue: boolean) {
this.$emit('before-enter');
requestAnimationFrame(() => {
this.checkStatus('enter');
if (this.status !== 'enter') {
return;
}
this.$emit('enter');
this.setData({
@ -65,9 +69,11 @@ export function transition(showDefaultValue: boolean) {
});
requestAnimationFrame(() => {
this.checkStatus('enter');
this.transitionEnded = false;
if (this.status !== 'enter') {
return;
}
this.transitionEnded = false;
this.setData({ classes: classNames['enter-to'] });
});
});
@ -86,7 +92,10 @@ export function transition(showDefaultValue: boolean) {
this.$emit('before-leave');
requestAnimationFrame(() => {
this.checkStatus('leave');
if (this.status !== 'leave') {
return;
}
this.$emit('leave');
this.setData({
@ -95,7 +104,10 @@ export function transition(showDefaultValue: boolean) {
});
requestAnimationFrame(() => {
this.checkStatus('leave');
if (this.status !== 'leave') {
return;
}
this.transitionEnded = false;
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() {
if (this.transitionEnded) {
return;