From 19fb55febf602c19e3ad989b2ba2a0a79518fb52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=89=E5=92=B2=E6=99=BA=E5=AD=90=20Kevin=20Deng?= Date: Tue, 12 Dec 2023 15:39:00 +0800 Subject: [PATCH] fix(runtime-vapor): custom directive instance closes #50 --- packages/runtime-vapor/src/directive.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/runtime-vapor/src/directive.ts b/packages/runtime-vapor/src/directive.ts index ab7ca782a..f255153fd 100644 --- a/packages/runtime-vapor/src/directive.ts +++ b/packages/runtime-vapor/src/directive.ts @@ -68,8 +68,9 @@ export function withDirectives( 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( const binding: DirectiveBinding = { dir, - instance: currentInstance, + instance, source, value: null, // set later oldValue: null, @@ -93,8 +94,9 @@ export function withDirectives( bindings.push(binding) callDirectiveHook(node, binding, 'created') + effect(() => { - if (!currentInstance!.isMountedRef.value) return + if (!instance.isMountedRef.value) return callDirectiveHook(node, binding, 'updated') }) }