8000 avoid v-model debounce on blur (fix #2028) · htylab/vue@81d38aa · GitHub
[go: up one dir, main page]

Skip to content

Commit 81d38aa

Browse files
committed
avoid v-model debounce on blur (fix vuejs#2028)
1 parent f9bbd20 commit 81d38aa

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

src/directive.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ Directive.prototype._bind = function () {
109109
if (this.bind) {
110110
this.bind()
111111
}
112+
this._bound = true
112113

113114
if (this.literal) {
114115
this.update && this.update(descriptor.raw)
@@ -156,7 +157,6 @@ Directive.prototype._bind = function () {
156157
this.update(watcher.value)
157158
}
158159
}
159-
this._bound = true
160160
}
161161

162162
/**

src/directives/public/model/text.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ export default {
5353
self.focused = false
5454
// do not sync value after fragment removal (#2017)
5555
if (!self._frag || self._frag.inserted) {
56-
self.listener()
56+
self.rawListener()
5757
}
5858
})
5959
}
6060

6161
// Now attach the main listener
62-
this.listener = function () {
62+
this.listener = this.rawListener = function () {
6363
if (composing || !self._bound) {
6464
return
6565
}

test/unit/specs/directives/public/model_spec.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,19 @@ describe('v-model', function () {
709709
}, 30)
710710
setTimeout(function () {
711711
expect(spy.calls.count()).toBe(1)
712+
expect(spy).toHaveBeenCalledWith('d', 'a')
712713
expect(vm.test).toBe('d')
713-
done()
714+
}, 150)
715+
setTimeout(function () {
716+
el.firstChild.value = 'e'
717+
// blur should trigger change instantly without debounce
718+
trigger(el.firstChild, 'blur')
719+
_.nextTick(function () {
720+
expect(spy.calls.count()).toBe(2)
721+
expect(spy).toHaveBeenCalledWith('e', 'd')
722+
expect(vm.test).toBe('e')
723+
done()
724+
})
714725
}, 200)
715726
})
716727

0 commit comments

Comments
 (0)
0