|
@@ -10,6 +10,7 @@ import {
|
|
|
} from './componentProps'
|
|
} from './componentProps'
|
|
|
|
|
|
|
|
import type { Data } from '@vue/shared'
|
|
import type { Data } from '@vue/shared'
|
|
|
|
|
+import { VaporLifecycleHooks } from './apiLifecycle'
|
|
|
|
|
|
|
|
export type Component = FunctionalComponent | ObjectComponent
|
|
export type Component = FunctionalComponent | ObjectComponent
|
|
|
|
|
|
|
@@ -24,6 +25,8 @@ export interface ObjectComponent {
|
|
|
render(ctx: any): Block
|
|
render(ctx: any): Block
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+type LifecycleHook<TFn = Function> = TFn[] | null
|
|
|
|
|
+
|
|
|
export interface ComponentInternalInstance {
|
|
export interface ComponentInternalInstance {
|
|
|
uid: number
|
|
uid: number
|
|
|
container: ParentNode
|
|
container: ParentNode
|
|
@@ -44,8 +47,66 @@ export interface ComponentInternalInstance {
|
|
|
|
|
|
|
|
// lifecycle
|
|
// lifecycle
|
|
|
get isMounted(): boolean
|
|
get isMounted(): boolean
|
|
|
|
|
+ get isUnmounted(): boolean
|
|
|
|
|
+ isUnmountedRef: Ref<boolean>
|
|
|
isMountedRef: Ref<boolean>
|
|
isMountedRef: Ref<boolean>
|
|
|
// TODO: registory of provides, appContext, lifecycles, ...
|
|
// TODO: registory of provides, appContext, lifecycles, ...
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_CREATE]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.CREATED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_MOUNT]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.MOUNTED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_UPDATE]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.UPDATED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_UNMOUNT]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.UNMOUNTED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.RENDER_TRACKED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.RENDER_TRIGGERED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.ACTIVATED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.DEACTIVATED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.ERROR_CAPTURED]: LifecycleHook
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ // [VaporLifecycleHooks.SERVER_PREFETCH]: LifecycleHook<() => Promise<unknown>>
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// TODO
|
|
// TODO
|
|
@@ -67,17 +128,17 @@ export const createComponentInstance = (
|
|
|
component: ObjectComponent | FunctionalComponent,
|
|
component: ObjectComponent | FunctionalComponent,
|
|
|
): ComponentInternalInstance => {
|
|
): ComponentInternalInstance => {
|
|
|
const isMountedRef = ref(false)
|
|
const isMountedRef = ref(false)
|
|
|
|
|
+ const isUnmountedRef = ref(false)
|
|
|
const instance: ComponentInternalInstance = {
|
|
const instance: ComponentInternalInstance = {
|
|
|
uid: uid++,
|
|
uid: uid++,
|
|
|
block: null,
|
|
block: null,
|
|
|
- container: null!, // set on mount
|
|
|
|
|
|
|
+ container: null!, // set on mountComponent
|
|
|
scope: new EffectScope(true /* detached */)!,
|
|
scope: new EffectScope(true /* detached */)!,
|
|
|
component,
|
|
component,
|
|
|
|
|
|
|
|
// resolved props and emits options
|
|
// resolved props and emits options
|
|
|
propsOptions: normalizePropsOptions(component),
|
|
propsOptions: normalizePropsOptions(component),
|
|
|
// emitsOptions: normalizeEmitsOptions(type, appContext), // TODO:
|
|
// emitsOptions: normalizeEmitsOptions(type, appContext), // TODO:
|
|
|
-
|
|
|
|
|
proxy: null,
|
|
proxy: null,
|
|
|
|
|
|
|
|
// state
|
|
// state
|
|
@@ -90,8 +151,68 @@ export const createComponentInstance = (
|
|
|
get isMounted() {
|
|
get isMounted() {
|
|
|
return isMountedRef.value
|
|
return isMountedRef.value
|
|
|
},
|
|
},
|
|
|
|
|
+ get isUnmounted() {
|
|
|
|
|
+ return isUnmountedRef.value
|
|
|
|
|
+ },
|
|
|
isMountedRef,
|
|
isMountedRef,
|
|
|
|
|
+ isUnmountedRef,
|
|
|
// TODO: registory of provides, appContext, lifecycles, ...
|
|
// TODO: registory of provides, appContext, lifecycles, ...
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_CREATE]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.CREATED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_MOUNT]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.MOUNTED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_UPDATE]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.UPDATED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.BEFORE_UNMOUNT]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.UNMOUNTED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.RENDER_TRACKED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.RENDER_TRIGGERED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.ACTIVATED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.DEACTIVATED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ [VaporLifecycleHooks.ERROR_CAPTURED]: null,
|
|
|
|
|
+ /**
|
|
|
|
|
+ * @internal
|
|
|
|
|
+ */
|
|
|
|
|
+ // [VaporLifecycleHooks.SERVER_PREFETCH]: null,
|
|
|
}
|
|
}
|
|
|
return instance
|
|
return instance
|
|
|
}
|
|
}
|