refactor(runtime-vapor): remove ref wrapper for mounted state

This commit is contained in:
三咲智子 Kevin Deng 2024-01-20 20:46:41 +08:00
parent 9d071e7c31
commit 6a26db2adc
No known key found for this signature in database
GPG Key ID: 69992F2250DFD93E
2 changed files with 8 additions and 30 deletions

View File

@ -1,10 +1,4 @@
import { import { EffectScope } from '@vue/reactivity'
EffectScope,
type Ref,
pauseTracking,
ref,
resetTracking,
} from '@vue/reactivity'
import { EMPTY_OBJ } from '@vue/shared' import { EMPTY_OBJ } from '@vue/shared'
import type { Block } from './render' import type { Block } from './render'
@ -51,11 +45,9 @@ export interface ComponentInternalInstance {
dirs: Map<Node, DirectiveBinding[]> dirs: Map<Node, DirectiveBinding[]>
// lifecycle // lifecycle
get isMounted(): boolean isMounted: boolean
get isUnmounted(): boolean isUnmounted: boolean
isUpdating: boolean isUpdating: boolean
isUnmountedRef: Ref<boolean>
isMountedRef: Ref<boolean>
// TODO: registory of provides, lifecycles, ... // TODO: registory of provides, lifecycles, ...
/** /**
* @internal * @internal
@ -140,8 +132,6 @@ let uid = 0
export const createComponentInstance = ( export const createComponentInstance = (
component: ObjectComponent | FunctionalComponent, component: ObjectComponent | FunctionalComponent,
): ComponentInternalInstance => { ): ComponentInternalInstance => {
const isMountedRef = ref(false)
const isUnmountedRef = ref(false)
const instance: ComponentInternalInstance = { const instance: ComponentInternalInstance = {
uid: uid++, uid: uid++,
block: null, block: null,
@ -163,21 +153,9 @@ export const createComponentInstance = (
dirs: new Map(), dirs: new Map(),
// lifecycle // lifecycle
get isMounted() { isMounted: false,
pauseTracking() isUnmounted: false,
const value = isMountedRef.value
resetTracking()
return value
},
get isUnmounted() {
pauseTracking()
const value = isUnmountedRef.value
resetTracking()
return value
},
isUpdating: false, isUpdating: false,
isMountedRef,
isUnmountedRef,
// TODO: registory of provides, appContext, lifecycles, ... // TODO: registory of provides, appContext, lifecycles, ...
/** /**
* @internal * @internal

View File

@ -75,7 +75,7 @@ export function mountComponent(
invokeDirectiveHook(instance, 'beforeMount') invokeDirectiveHook(instance, 'beforeMount')
insert(block, instance.container) insert(block, instance.container)
instance.isMountedRef.value = true instance.isMounted = true
// hook: mounted // hook: mounted
invokeDirectiveHook(instance, 'mounted') invokeDirectiveHook(instance, 'mounted')
@ -94,8 +94,8 @@ export function unmountComponent(instance: ComponentInternalInstance) {
scope.stop() scope.stop()
block && remove(block, container) block && remove(block, container)
instance.isMountedRef.value = false instance.isMounted = false
instance.isUnmountedRef.value = true instance.isUnmounted = true
// hook: unmounted // hook: unmounted
invokeDirectiveHook(instance, 'unmounted') invokeDirectiveHook(instance, 'unmounted')