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

revert: fix(v-model): fix input listener with modifier blocking v-model update

This reverts commit 6f312d636c3d6049dc9e60007f88ea871b8e8173 because the change
is no longer needed after switching nextTick to use MessageChannel.
Evan You 8 лет назад
Родитель
Сommit
62405aa903
2 измененных файлов с 4 добавлено и 29 удалено
  1. 2 22
      src/core/vdom/helpers/update-listeners.js
  2. 2 7
      test/unit/features/directives/model-text.spec.js

+ 2 - 22
src/core/vdom/helpers/update-listeners.js

@@ -5,11 +5,9 @@ import { cached, isUndef } from 'shared/util'
 
 
 const normalizeEvent = cached((name: string): {
 const normalizeEvent = cached((name: string): {
   name: string,
   name: string,
-  plain: boolean,
   once: boolean,
   once: boolean,
   capture: boolean,
   capture: boolean,
-  passive: boolean,
-  handler?: Function
+  passive: boolean
 } => {
 } => {
   const passive = name.charAt(0) === '&'
   const passive = name.charAt(0) === '&'
   name = passive ? name.slice(1) : name
   name = passive ? name.slice(1) : name
@@ -17,10 +15,8 @@ const normalizeEvent = cached((name: string): {
   name = once ? name.slice(1) : name
   name = once ? name.slice(1) : name
   const capture = name.charAt(0) === '!'
   const capture = name.charAt(0) === '!'
   name = capture ? name.slice(1) : name
   name = capture ? name.slice(1) : name
-  const plain = !(passive || once || capture)
   return {
   return {
     name,
     name,
-    plain,
     once,
     once,
     capture,
     capture,
     passive
     passive
@@ -44,11 +40,6 @@ export function createFnInvoker (fns: Function | Array<Function>): Function {
   return invoker
   return invoker
 }
 }
 
 
-// #6552
-function prioritizePlainEvents (a, b) {
-  return a.plain ? -1 : b.plain ? 1 : 0
-}
-
 export function updateListeners (
 export function updateListeners (
   on: Object,
   on: Object,
   oldOn: Object,
   oldOn: Object,
@@ -57,13 +48,10 @@ export function updateListeners (
   vm: Component
   vm: Component
 ) {
 ) {
   let name, cur, old, event
   let name, cur, old, event
-  const toAdd = []
-  let hasModifier = false
   for (name in on) {
   for (name in on) {
     cur = on[name]
     cur = on[name]
     old = oldOn[name]
     old = oldOn[name]
     event = normalizeEvent(name)
     event = normalizeEvent(name)
-    if (!event.plain) hasModifier = true
     if (isUndef(cur)) {
     if (isUndef(cur)) {
       process.env.NODE_ENV !== 'production' && warn(
       process.env.NODE_ENV !== 'production' && warn(
         `Invalid handler for event "${event.name}": got ` + String(cur),
         `Invalid handler for event "${event.name}": got ` + String(cur),
@@ -73,20 +61,12 @@ export function updateListeners (
       if (isUndef(cur.fns)) {
       if (isUndef(cur.fns)) {
         cur = on[name] = createFnInvoker(cur)
         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) {
     } else if (cur !== old) {
       old.fns = cur
       old.fns = cur
       on[name] = old
       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) {
   for (name in oldOn) {
     if (isUndef(on[name])) {
     if (isUndef(on[name])) {
       event = normalizeEvent(name)
       event = normalizeEvent(name)

+ 2 - 7
test/unit/features/directives/model-text.spec.js

@@ -315,13 +315,8 @@ describe('Directive v-model text', () => {
     })
     })
 
 
     // #6552
     // #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 => {
     it('should not block input when another input listener with modifier is used', done => {
       const vm = new Vue({
       const vm = new Vue({
         data: {
         data: {