Просмотр исходного кода

detect synchronous done callback in transitions (fix #1244)

Evan You 10 лет назад
Родитель
Сommit
70944fb936
1 измененных файлов с 11 добавлено и 0 удалено
  1. 11 0
      src/transition/transition.js

+ 11 - 0
src/transition/transition.js

@@ -35,6 +35,7 @@ function Transition (el, id, hooks, vm) {
   this.op =
   this.cb = null
   this.justEntered = false
+  this.entered = this.left = false
   this.typeCache = {}
   // bind
   var self = this
@@ -77,7 +78,11 @@ p.enter = function (op, cb) {
   this.cb = cb
   addClass(this.el, this.enterClass)
   op()
+  this.entered = false
   this.callHookWithCb('enter')
+  if (this.entered) {
+    return // user called done synchronously.
+  }
   this.cancel = this.hooks && this.hooks.enterCancelled
   queue.push(this.enterNextTick)
 }
@@ -115,6 +120,7 @@ p.enterNextTick = function () {
  */
 
 p.enterDone = function () {
+  this.entered = true
   this.cancel = this.pendingJsCb = null
   removeClass(this.el, this.enterClass)
   this.callHook('afterEnter')
@@ -148,7 +154,11 @@ p.leave = function (op, cb) {
   this.op = op
   this.cb = cb
   addClass(this.el, this.leaveClass)
+  this.left = false
   this.callHookWithCb('leave')
+  if (this.left) {
+    return // user called done synchronously.
+  }
   this.cancel = this.hooks && this.hooks.leaveCancelled
   // only need to handle leaveDone if
   // 1. the transition is already done (synchronously called
@@ -187,6 +197,7 @@ p.leaveNextTick = function () {
  */
 
 p.leaveDone = function () {
+  this.left = true
   this.cancel = this.pendingJsCb = null
   this.op()
   removeClass(this.el, this.leaveClass)