Skip to content

Commit

Permalink
avoid v-model debounce on blur (fix vuejs#2028)
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Dec 15, 2015
1 parent f9bbd20 commit 81d38aa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -156,7 +157,6 @@ Directive.prototype._bind = function () {
this.update(watcher.value)
}
}
this._bound = true
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/directives/public/model/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 12 additions & 1 deletion test/unit/specs/directives/public/model_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})

Expand Down

0 comments on commit 81d38aa

Please sign in to comment.