refactor: tweaks
This commit is contained in:
parent
1b8236615e
commit
a6aa64b0cc
@ -28,6 +28,7 @@ import {
|
|||||||
} from '@vue/shared'
|
} from '@vue/shared'
|
||||||
import { SuspenseBoundary } from './components/Suspense'
|
import { SuspenseBoundary } from './components/Suspense'
|
||||||
import { CompilerError, CompilerOptions } from '@vue/compiler-core'
|
import { CompilerError, CompilerOptions } from '@vue/compiler-core'
|
||||||
|
import { currentRenderingInstance } from './componentRenderUtils'
|
||||||
|
|
||||||
export type Data = { [key: string]: unknown }
|
export type Data = { [key: string]: unknown }
|
||||||
|
|
||||||
@ -112,6 +113,7 @@ export interface ComponentInternalInstance {
|
|||||||
sink: { [key: string]: any }
|
sink: { [key: string]: any }
|
||||||
|
|
||||||
// lifecycle
|
// lifecycle
|
||||||
|
isMounted: boolean
|
||||||
isUnmounted: boolean
|
isUnmounted: boolean
|
||||||
isDeactivated: boolean
|
isDeactivated: boolean
|
||||||
[LifecycleHooks.BEFORE_CREATE]: LifecycleHook
|
[LifecycleHooks.BEFORE_CREATE]: LifecycleHook
|
||||||
@ -179,6 +181,7 @@ export function createComponentInstance(
|
|||||||
|
|
||||||
// lifecycle hooks
|
// lifecycle hooks
|
||||||
// not using enums here because it results in computed properties
|
// not using enums here because it results in computed properties
|
||||||
|
isMounted: false,
|
||||||
isUnmounted: false,
|
isUnmounted: false,
|
||||||
isDeactivated: false,
|
isDeactivated: false,
|
||||||
bc: null,
|
bc: null,
|
||||||
@ -217,7 +220,7 @@ export let currentInstance: ComponentInternalInstance | null = null
|
|||||||
export let currentSuspense: SuspenseBoundary | null = null
|
export let currentSuspense: SuspenseBoundary | null = null
|
||||||
|
|
||||||
export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
|
export const getCurrentInstance: () => ComponentInternalInstance | null = () =>
|
||||||
currentInstance
|
currentInstance || currentRenderingInstance
|
||||||
|
|
||||||
export const setCurrentInstance = (
|
export const setCurrentInstance = (
|
||||||
instance: ComponentInternalInstance | null
|
instance: ComponentInternalInstance | null
|
||||||
|
@ -219,7 +219,6 @@ export interface SuspenseBoundary<
|
|||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
setupRenderEffect: (
|
setupRenderEffect: (
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
parentComponent: ComponentInternalInstance | null,
|
|
||||||
parentSuspense: SuspenseBoundary<HostNode, HostElement> | null,
|
parentSuspense: SuspenseBoundary<HostNode, HostElement> | null,
|
||||||
initialVNode: VNode<HostNode, HostElement>,
|
initialVNode: VNode<HostNode, HostElement>,
|
||||||
container: HostElement,
|
container: HostElement,
|
||||||
@ -419,7 +418,6 @@ function createSuspenseBoundary<HostNode, HostElement>(
|
|||||||
handleSetupResult(instance, asyncSetupResult, suspense)
|
handleSetupResult(instance, asyncSetupResult, suspense)
|
||||||
setupRenderEffect(
|
setupRenderEffect(
|
||||||
instance,
|
instance,
|
||||||
parentComponent,
|
|
||||||
suspense,
|
suspense,
|
||||||
vnode,
|
vnode,
|
||||||
// component may have been moved before resolve
|
// component may have been moved before resolve
|
||||||
|
@ -7,22 +7,23 @@ import { cloneVNode, Comment, isSameVNodeType, VNode } from '../vnode'
|
|||||||
import { warn } from '../warning'
|
import { warn } from '../warning'
|
||||||
import { isKeepAlive } from './KeepAlive'
|
import { isKeepAlive } from './KeepAlive'
|
||||||
import { toRaw } from '@vue/reactivity'
|
import { toRaw } from '@vue/reactivity'
|
||||||
import { onMounted } from '../apiLifecycle'
|
|
||||||
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
|
import { callWithAsyncErrorHandling, ErrorCodes } from '../errorHandling'
|
||||||
import { ShapeFlags } from '../shapeFlags'
|
import { ShapeFlags } from '../shapeFlags'
|
||||||
|
|
||||||
// Using camel case here makes it easier to use in render functions & JSX.
|
|
||||||
// In templates these will be written as @before-enter="xxx"
|
|
||||||
// The compiler has special handling to convert them into the proper cases.
|
|
||||||
export interface TransitionProps {
|
export interface TransitionProps {
|
||||||
mode?: 'in-out' | 'out-in' | 'default'
|
mode?: 'in-out' | 'out-in' | 'default'
|
||||||
appear?: boolean
|
appear?: boolean
|
||||||
|
|
||||||
// If true, indicates this is a transition that doesn't actually insert/remove
|
// If true, indicates this is a transition that doesn't actually insert/remove
|
||||||
// the element, but toggles the show / hidden status instead.
|
// the element, but toggles the show / hidden status instead.
|
||||||
// The transition hooks are injected, but will be skipped by the renderer.
|
// The transition hooks are injected, but will be skipped by the renderer.
|
||||||
// Instead, a custom directive can control the transition by calling the
|
// Instead, a custom directive can control the transition by calling the
|
||||||
// injected hooks (e.g. v-show).
|
// injected hooks (e.g. v-show).
|
||||||
persisted?: boolean
|
persisted?: boolean
|
||||||
|
|
||||||
|
// Hooks. Using camel casef for easier usage in render functions & JSX.
|
||||||
|
// In templates these will be written as @before-enter="xxx"
|
||||||
|
// The compiler has special handling to convert them into the proper cases.
|
||||||
// enter
|
// enter
|
||||||
onBeforeEnter?: (el: any) => void
|
onBeforeEnter?: (el: any) => void
|
||||||
onEnter?: (el: any, done: () => void) => void
|
onEnter?: (el: any, done: () => void) => void
|
||||||
@ -49,13 +50,8 @@ const TransitionImpl = {
|
|||||||
name: `BaseTransition`,
|
name: `BaseTransition`,
|
||||||
setup(props: TransitionProps, { slots }: SetupContext) {
|
setup(props: TransitionProps, { slots }: SetupContext) {
|
||||||
const instance = getCurrentInstance()!
|
const instance = getCurrentInstance()!
|
||||||
let isLeaving = false
|
|
||||||
let isMounted = false
|
|
||||||
const pendingCallbacks: PendingCallbacks = {}
|
const pendingCallbacks: PendingCallbacks = {}
|
||||||
|
let isLeaving = false
|
||||||
onMounted(() => {
|
|
||||||
isMounted = true
|
|
||||||
})
|
|
||||||
|
|
||||||
const callTransitionHook: TransitionHookCaller = (hook, args) => {
|
const callTransitionHook: TransitionHookCaller = (hook, args) => {
|
||||||
hook &&
|
hook &&
|
||||||
@ -101,7 +97,7 @@ const TransitionImpl = {
|
|||||||
const transitionHooks = (child.transition = resolveTransitionHooks(
|
const transitionHooks = (child.transition = resolveTransitionHooks(
|
||||||
rawProps,
|
rawProps,
|
||||||
callTransitionHook,
|
callTransitionHook,
|
||||||
isMounted,
|
instance.isMounted,
|
||||||
pendingCallbacks,
|
pendingCallbacks,
|
||||||
performDelayedLeave
|
performDelayedLeave
|
||||||
))
|
))
|
||||||
|
@ -885,7 +885,6 @@ export function createRenderer<
|
|||||||
|
|
||||||
setupRenderEffect(
|
setupRenderEffect(
|
||||||
instance,
|
instance,
|
||||||
parentComponent,
|
|
||||||
parentSuspense,
|
parentSuspense,
|
||||||
initialVNode,
|
initialVNode,
|
||||||
container,
|
container,
|
||||||
@ -900,7 +899,6 @@ export function createRenderer<
|
|||||||
|
|
||||||
function setupRenderEffect(
|
function setupRenderEffect(
|
||||||
instance: ComponentInternalInstance,
|
instance: ComponentInternalInstance,
|
||||||
parentComponent: ComponentInternalInstance | null,
|
|
||||||
parentSuspense: HostSuspenseBoundary | null,
|
parentSuspense: HostSuspenseBoundary | null,
|
||||||
initialVNode: HostVNode,
|
initialVNode: HostVNode,
|
||||||
container: HostElement,
|
container: HostElement,
|
||||||
@ -908,9 +906,8 @@ export function createRenderer<
|
|||||||
isSVG: boolean
|
isSVG: boolean
|
||||||
) {
|
) {
|
||||||
// create reactive effect for rendering
|
// create reactive effect for rendering
|
||||||
let mounted = false
|
|
||||||
instance.update = effect(function componentEffect() {
|
instance.update = effect(function componentEffect() {
|
||||||
if (!mounted) {
|
if (!instance.isMounted) {
|
||||||
const subTree = (instance.subTree = renderComponentRoot(instance))
|
const subTree = (instance.subTree = renderComponentRoot(instance))
|
||||||
// beforeMount hook
|
// beforeMount hook
|
||||||
if (instance.bm !== null) {
|
if (instance.bm !== null) {
|
||||||
@ -929,7 +926,7 @@ export function createRenderer<
|
|||||||
) {
|
) {
|
||||||
queuePostRenderEffect(instance.a, parentSuspense)
|
queuePostRenderEffect(instance.a, parentSuspense)
|
||||||
}
|
}
|
||||||
mounted = true
|
instance.isMounted = true
|
||||||
} else {
|
} else {
|
||||||
// updateComponent
|
// updateComponent
|
||||||
// This is triggered by mutation of component's own state (next: null)
|
// This is triggered by mutation of component's own state (next: null)
|
||||||
|
@ -3,10 +3,10 @@ import {
|
|||||||
TransitionProps,
|
TransitionProps,
|
||||||
h,
|
h,
|
||||||
warn,
|
warn,
|
||||||
FunctionalComponent
|
FunctionalComponent,
|
||||||
|
getCurrentInstance
|
||||||
} from '@vue/runtime-core'
|
} from '@vue/runtime-core'
|
||||||
import { isObject } from '@vue/shared'
|
import { isObject } from '@vue/shared'
|
||||||
import { currentRenderingInstance } from 'packages/runtime-core/src/componentRenderUtils'
|
|
||||||
|
|
||||||
const TRANSITION = 'transition'
|
const TRANSITION = 'transition'
|
||||||
const ANIMATION = 'animation'
|
const ANIMATION = 'animation'
|
||||||
@ -71,7 +71,7 @@ function resolveCSSTransitionProps({
|
|||||||
const { appear, onBeforeEnter, onEnter, onLeave } = baseProps
|
const { appear, onBeforeEnter, onEnter, onLeave } = baseProps
|
||||||
|
|
||||||
// is appearing
|
// is appearing
|
||||||
if (appear && !currentRenderingInstance!.subTree) {
|
if (appear && !getCurrentInstance()!.isMounted) {
|
||||||
enterFromClass = appearFromClass
|
enterFromClass = appearFromClass
|
||||||
enterActiveClass = appearActiveClass
|
enterActiveClass = appearActiveClass
|
||||||
enterToClass = appearToClass
|
enterToClass = appearToClass
|
||||||
|
Loading…
Reference in New Issue
Block a user