Skip to content

Commit

Permalink
revert: fix(v-model): fix input listener with modifier blocking v-mod…
Browse files Browse the repository at this point in the history
…el update

This reverts commit 6f312d6 because the change
is no longer needed after switching nextTick to use MessageChannel.
  • Loading branch information
yyx990803 committed Oct 9, 2017
1 parent 405d8e9 commit 62405aa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 29 deletions.
24 changes: 2 additions & 22 deletions src/core/vdom/helpers/update-listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ import { cached, isUndef } from 'shared/util'

const normalizeEvent = cached((name: string): {
name: string,
plain: boolean,
once: boolean,
capture: boolean,
passive: boolean,
handler?: Function
passive: boolean
} => {
const passive = name.charAt(0) === '&'
name = passive ? name.slice(1) : name
const once = name.charAt(0) === '~' // Prefixed last, checked first
name = once ? name.slice(1) : name
const capture = name.charAt(0) === '!'
name = capture ? name.slice(1) : name
const plain = !(passive || once || capture)
return {
name,
plain,
once,
capture,
passive
Expand All @@ -44,11 +40,6 @@ export function createFnInvoker (fns: Function | Array<Function>): Function {
return invoker
}

// #6552
function prioritizePlainEvents (a, b) {
return a.plain ? -1 : b.plain ? 1 : 0
}

export function updateListeners (
on: Object,
oldOn: Object,
Expand All @@ -57,13 +48,10 @@ export function updateListeners (
vm: Component
) {
let name, cur, old, event
const toAdd = []
let hasModifier = false
for (name in on) {
cur = on[name]
old = oldOn[name]
event = normalizeEvent(name)
if (!event.plain) hasModifier = true
if (isUndef(cur)) {
process.env.NODE_ENV !== 'production' && warn(
`Invalid handler for event "${event.name}": got ` + String(cur),
Expand All @@ -73,20 +61,12 @@ export function updateListeners (
if (isUndef(cur.fns)) {
cur = on[name] = createFnInvoker(cur)
}
event.handler = cur
toAdd.push(event)
add(event.name, cur, event.once, event.capture, event.passive)
} else if (cur !== old) {
old.fns = cur
on[name] = old
}
}
if (toAdd.length) {
if (hasModifier) toAdd.sort(prioritizePlainEvents)
for (let i = 0; i < toAdd.length; i++) {
const event = toAdd[i]
add(event.name, event.handler, event.once, event.capture, event.passive)
}
}
for (name in oldOn) {
if (isUndef(on[name])) {
event = normalizeEvent(name)
Expand Down
9 changes: 2 additions & 7 deletions test/unit/features/directives/model-text.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,13 +315,8 @@ describe('Directive v-model text', () => {
})

// #6552
// Root cause: input listeners with modifiers are added as a separate
// DOM listener. If a change is triggered inside this listener, an update
// will happen before the second listener is fired! (obviously microtasks
// can be processed in between DOM events on the same element)
// This causes the domProps module to receive state that has not been
// updated by v-model yet (because v-model's listener has not fired yet)
// Solution: make sure to always fire v-model's listener first
// This was original introduced due to the microtask between DOM events issue
// but fixed after switching to MessageChannel.
it('should not block input when another input listener with modifier is used', done => {
const vm = new Vue({
data: {
Expand Down

0 comments on commit 62405aa

Please sign in to comment.