Skip to content

Commit

Permalink
refactor(runtime-vapor): remove ref wrapper for mounted state
Browse files Browse the repository at this point in the history
  • Loading branch information
sxzz committed Jan 20, 2024
1 parent 9d071e7 commit 6a26db2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 30 deletions.
32 changes: 5 additions & 27 deletions packages/runtime-vapor/src/component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import {
EffectScope,
type Ref,
pauseTracking,
ref,
resetTracking,
} from '@vue/reactivity'
import { EffectScope } from '@vue/reactivity'

import { EMPTY_OBJ } from '@vue/shared'
import type { Block } from './render'
Expand Down Expand Up @@ -51,11 +45,9 @@ export interface ComponentInternalInstance {
dirs: Map<Node, DirectiveBinding[]>

// lifecycle
get isMounted(): boolean
get isUnmounted(): boolean
isMounted: boolean
isUnmounted: boolean
isUpdating: boolean
isUnmountedRef: Ref<boolean>
isMountedRef: Ref<boolean>
// TODO: registory of provides, lifecycles, ...
/**
* @internal
Expand Down Expand Up @@ -140,8 +132,6 @@ let uid = 0
export const createComponentInstance = (
component: ObjectComponent | FunctionalComponent,
): ComponentInternalInstance => {
const isMountedRef = ref(false)
const isUnmountedRef = ref(false)
const instance: ComponentInternalInstance = {
uid: uid++,
block: null,
Expand All @@ -163,21 +153,9 @@ export const createComponentInstance = (
dirs: new Map(),

// lifecycle
get isMounted() {
pauseTracking()
const value = isMountedRef.value
resetTracking()
return value
},
get isUnmounted() {
pauseTracking()
const value = isUnmountedRef.value
resetTracking()
return value
},
isMounted: false,
isUnmounted: false,
isUpdating: false,
isMountedRef,
isUnmountedRef,
// TODO: registory of provides, appContext, lifecycles, ...
/**
* @internal
Expand Down
6 changes: 3 additions & 3 deletions packages/runtime-vapor/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function mountComponent(
invokeDirectiveHook(instance, 'beforeMount')

insert(block, instance.container)
instance.isMountedRef.value = true
instance.isMounted = true

// hook: mounted
invokeDirectiveHook(instance, 'mounted')
Expand All @@ -94,8 +94,8 @@ export function unmountComponent(instance: ComponentInternalInstance) {

scope.stop()
block && remove(block, container)
instance.isMountedRef.value = false
instance.isUnmountedRef.value = true
instance.isMounted = false
instance.isUnmounted = true

// hook: unmounted
invokeDirectiveHook(instance, 'unmounted')
Expand Down

0 comments on commit 6a26db2

Please sign in to comment.