1- import {
2- type Component ,
3- createComponentInstance ,
4- setCurrentInstance ,
5- } from './component'
1+ import { type Component , createComponentInstance } from './component'
62import { setupComponent } from './apiRender'
73import type { RawProps } from './componentProps'
84import type { RawSlots } from './componentSlots'
95import { withAttrs } from './componentAttrs'
106import { getCurrentScope } from '@vue/reactivity'
117import type { BlockEffectScope } from './blockEffectScope'
12- import {
13- type Directive ,
14- type DirectiveHookName ,
15- invokeDirectiveHook ,
16- } from './directives'
8+ import { setDirectiveBinding } from './directives'
179import { VaporLifecycleHooks } from './enums'
18- import { NOOP , invokeArrayFns } from '@vue/shared '
10+ import { scheduleLifecycleHooks } from './componentLifecycle '
1911
2012export function createComponent (
2113 comp : Component ,
@@ -33,58 +25,39 @@ export function createComponent(
3325 )
3426 setupComponent ( instance , singleRoot )
3527
36- const directiveBindingsMap = ( parentScope . dirs ||= new Map ( ) )
37- const dir : Directive = {
38- beforeMount : passDirectives (
39- VaporLifecycleHooks . BEFORE_MOUNT ,
40- 'beforeMount' ,
41- ) ,
42- mounted : passDirectives (
43- VaporLifecycleHooks . MOUNTED ,
44- 'mounted' ,
45- ( ) => ( instance . isMounted = true ) ,
46- true ,
47- ) ,
48- beforeUnmount : passDirectives (
49- VaporLifecycleHooks . BEFORE_UNMOUNT ,
50- 'beforeUnmount' ,
51- ) ,
52- unmounted : passDirectives (
53- VaporLifecycleHooks . UNMOUNTED ,
54- 'unmounted' ,
55- ( ) => ( instance . isUnmounted = true ) ,
56- true ,
57- ) ,
58- }
59- directiveBindingsMap . set ( instance , [
60- { dir, instance, value : null , oldValue : undefined } ,
61- ] )
28+ setDirectiveBinding (
29+ instance ,
30+ instance ,
31+ {
32+ beforeMount : scheduleLifecycleHooks (
33+ instance ,
34+ VaporLifecycleHooks . BEFORE_MOUNT ,
35+ 'beforeMount' ,
36+ ) ,
37+ mounted : scheduleLifecycleHooks (
38+ instance ,
39+ VaporLifecycleHooks . MOUNTED ,
40+ 'mounted' ,
41+ ( ) => ( instance . isMounted = true ) ,
42+ true ,
43+ ) ,
44+ beforeUnmount : scheduleLifecycleHooks (
45+ instance ,
46+ VaporLifecycleHooks . BEFORE_UNMOUNT ,
47+ 'beforeUnmount' ,
48+ ) ,
49+ unmounted : scheduleLifecycleHooks (
50+ instance ,
51+ VaporLifecycleHooks . UNMOUNTED ,
52+ 'unmounted' ,
53+ ( ) => ( instance . isUnmounted = true ) ,
54+ true ,
55+ ) ,
56+ } ,
57+ null ,
58+ undefined ,
59+ parentScope ,
60+ )
6261
6362 return instance
64-
65- function passDirectives (
66- lifecycle : VaporLifecycleHooks ,
67- directive : DirectiveHookName ,
68- cb = NOOP ,
69- reverse ?: boolean ,
70- ) {
71- const hooks = reverse
72- ? [ cb , callDirHooks , callLifecycleHooks ]
73- : [ callLifecycleHooks , callDirHooks , cb ]
74-
75- return ( ) => invokeArrayFns ( hooks )
76-
77- function callDirHooks ( ) {
78- invokeDirectiveHook ( instance , directive , instance . scope )
79- }
80- function callLifecycleHooks ( ) {
81- // lifecycle hooks may be mounted halfway.
82- const lifecycleHooks = instance [ lifecycle ]
83- if ( lifecycleHooks && lifecycleHooks . length ) {
84- const reset = setCurrentInstance ( instance )
85- instance . scope . run ( ( ) => invokeArrayFns ( lifecycleHooks ) )
86- reset ( )
87- }
88- }
89- }
9063}
0 commit comments