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

fix(runtime-vapor): custom directive instance

closes #50
三咲智子 Kevin Deng 2 лет назад
Родитель
Сommit
19fb55febf
1 измененных файлов с 6 добавлено и 4 удалено
  1. 6 4
      packages/runtime-vapor/src/directive.ts

+ 6 - 4
packages/runtime-vapor/src/directive.ts

@@ -68,8 +68,9 @@ export function withDirectives<T extends Node>(
     return node
   }
 
-  if (!currentInstance.dirs.has(node)) currentInstance.dirs.set(node, [])
-  const bindings = currentInstance.dirs.get(node)!
+  const instance = currentInstance
+  if (!instance.dirs.has(node)) instance.dirs.set(node, [])
+  const bindings = instance.dirs.get(node)!
 
   for (const directive of directives) {
     let [dir, source, arg, modifiers] = directive
@@ -83,7 +84,7 @@ export function withDirectives<T extends Node>(
 
     const binding: DirectiveBinding = {
       dir,
-      instance: currentInstance,
+      instance,
       source,
       value: null, // set later
       oldValue: null,
@@ -93,8 +94,9 @@ export function withDirectives<T extends Node>(
     bindings.push(binding)
 
     callDirectiveHook(node, binding, 'created')
+
     effect(() => {
-      if (!currentInstance!.isMountedRef.value) return
+      if (!instance.isMountedRef.value) return
       callDirectiveHook(node, binding, 'updated')
     })
   }