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

ensure mergeVNodeHook does not inject duplicate hooks

Evan You 9 лет назад
Родитель
Сommit
ed2085974b
3 измененных файлов с 9 добавлено и 13 удалено
  1. 0 1
      flow/vnode.js
  2. 7 3
      src/core/vdom/helpers.js
  3. 2 9
      src/platforms/web/runtime/modules/transition.js

+ 0 - 1
flow/vnode.js

@@ -45,7 +45,6 @@ declare interface VNodeData {
   on?: ?{ [key: string]: Function | Array<Function> };
   nativeOn?: { [key: string]: Function | Array<Function> };
   transition?: Object;
-  transitionInjected?: boolean; // marker for transition insert hook injection
   show?: boolean; // marker for v-show
   inlineTemplate?: {
     render: Function;

+ 7 - 3
src/core/vdom/helpers.js

@@ -63,9 +63,13 @@ export function getFirstComponentChild (children: ?Array<any>) {
 export function mergeVNodeHook (def: Object, key: string, hook: Function) {
   const oldHook = def[key]
   if (oldHook) {
-    def[key] = function () {
-      oldHook.apply(this, arguments)
-      hook.apply(this, arguments)
+    const injectedHash = def.__injected || (def.__injected = {})
+    if (!injectedHash[key]) {
+      injectedHash[key] = true
+      def[key] = function () {
+        oldHook.apply(this, arguments)
+        hook.apply(this, arguments)
+      }
     }
   } else {
     def[key] = hook

+ 2 - 9
src/platforms/web/runtime/modules/transition.js

@@ -94,21 +94,14 @@ export function enter (vnode: VNodeWithData) {
 
   if (!vnode.data.show) {
     // remove pending leave element on enter by injecting an insert hook
-    var hooks = vnode.data.hook || (vnode.data.hook = {})
-    hooks._transitionInsert = () => {
+    mergeVNodeHook(vnode.data.hook || (vnode.data.hook = {}), 'insert', () => {
       const parent = el.parentNode
       const pendingNode = parent && parent._pending && parent._pending[vnode.key]
       if (pendingNode && pendingNode.tag === vnode.tag && pendingNode.elm._leaveCb) {
         pendingNode.elm._leaveCb()
       }
       enterHook && enterHook(el, cb)
-    }
-    if (!vnode.data.transitionInjected) {
-      vnode.data.transitionInjected = true
-      mergeVNodeHook(hooks, 'insert', () => {
-        hooks._transitionInsert()
-      })
-    }
+    })
   }
 
   // start enter transition