Преглед изворни кода

avoid v-model debounce on blur (fix #2028)

Evan You пре 10 година
родитељ
комит
81d38aa1d0

+ 1 - 1
src/directive.js

@@ -109,6 +109,7 @@ Directive.prototype._bind = function () {
   if (this.bind) {
     this.bind()
   }
+  this._bound = true
 
   if (this.literal) {
     this.update && this.update(descriptor.raw)
@@ -156,7 +157,6 @@ Directive.prototype._bind = function () {
       this.update(watcher.value)
     }
   }
-  this._bound = true
 }
 
 /**

+ 2 - 2
src/directives/public/model/text.js

@@ -53,13 +53,13 @@ export default {
         self.focused = false
         // do not sync value after fragment removal (#2017)
         if (!self._frag || self._frag.inserted) {
-          self.listener()
+          self.rawListener()
         }
       })
     }
 
     // Now attach the main listener
-    this.listener = function () {
+    this.listener = this.rawListener = function () {
       if (composing || !self._bound) {
         return
       }

+ 12 - 1
test/unit/specs/directives/public/model_spec.js

@@ -709,8 +709,19 @@ describe('v-model', function () {
     }, 30)
     setTimeout(function () {
       expect(spy.calls.count()).toBe(1)
+      expect(spy).toHaveBeenCalledWith('d', 'a')
       expect(vm.test).toBe('d')
-      done()
+    }, 150)
+    setTimeout(function () {
+      el.firstChild.value = 'e'
+      // blur should trigger change instantly without debounce
+      trigger(el.firstChild, 'blur')
+      _.nextTick(function () {
+        expect(spy.calls.count()).toBe(2)
+        expect(spy).toHaveBeenCalledWith('e', 'd')
+        expect(vm.test).toBe('e')
+        done()
+      })
     }, 200)
   })