wip(vapor): corresponding runtime behavior for if/for/slot-outlet post compiler change
This commit is contained in:
parent
9722574744
commit
f6d7b90195
|
@ -22,6 +22,8 @@ import { currentInstance, isVaporComponent } from './component'
|
||||||
import type { DynamicSlot } from './componentSlots'
|
import type { DynamicSlot } from './componentSlots'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
import { VaporVForFlags } from '../../shared/src/vaporFlags'
|
import { VaporVForFlags } from '../../shared/src/vaporFlags'
|
||||||
|
import { isHydrating, locateHydrationNode } from './dom/hydration'
|
||||||
|
import { insertionAnchor, insertionParent } from './insertionState'
|
||||||
|
|
||||||
class ForBlock extends VaporFragment {
|
class ForBlock extends VaporFragment {
|
||||||
scope: EffectScope | undefined
|
scope: EffectScope | undefined
|
||||||
|
@ -56,7 +58,6 @@ type ResolvedSource = {
|
||||||
keys?: string[]
|
keys?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! #__NO_SIDE_EFFECTS__ */
|
|
||||||
export const createFor = (
|
export const createFor = (
|
||||||
src: () => Source,
|
src: () => Source,
|
||||||
renderItem: (
|
renderItem: (
|
||||||
|
@ -66,12 +67,18 @@ export const createFor = (
|
||||||
) => Block,
|
) => Block,
|
||||||
getKey?: (item: any, key: any, index?: number) => any,
|
getKey?: (item: any, key: any, index?: number) => any,
|
||||||
flags = 0,
|
flags = 0,
|
||||||
// hydrationNode?: Node,
|
|
||||||
): VaporFragment => {
|
): VaporFragment => {
|
||||||
|
const _insertionParent = insertionParent
|
||||||
|
const _insertionAnchor = insertionAnchor
|
||||||
|
if (isHydrating) {
|
||||||
|
locateHydrationNode()
|
||||||
|
}
|
||||||
|
|
||||||
let isMounted = false
|
let isMounted = false
|
||||||
let oldBlocks: ForBlock[] = []
|
let oldBlocks: ForBlock[] = []
|
||||||
let newBlocks: ForBlock[]
|
let newBlocks: ForBlock[]
|
||||||
let parent: ParentNode | undefined | null
|
let parent: ParentNode | undefined | null
|
||||||
|
// TODO handle this in hydration
|
||||||
const parentAnchor = __DEV__ ? createComment('for') : createTextNode()
|
const parentAnchor = __DEV__ ? createComment('for') : createTextNode()
|
||||||
const frag = new VaporFragment(oldBlocks)
|
const frag = new VaporFragment(oldBlocks)
|
||||||
const instance = currentInstance!
|
const instance = currentInstance!
|
||||||
|
@ -356,6 +363,11 @@ export const createFor = (
|
||||||
} else {
|
} else {
|
||||||
renderEffect(renderList)
|
renderEffect(renderList)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isHydrating && _insertionParent) {
|
||||||
|
insert(frag, _insertionParent, _insertionAnchor)
|
||||||
|
}
|
||||||
|
|
||||||
return frag
|
return frag
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { type Block, type BlockFn, DynamicFragment } from './block'
|
import { type Block, type BlockFn, DynamicFragment, insert } from './block'
|
||||||
|
import { isHydrating, locateHydrationNode } from './dom/hydration'
|
||||||
|
import { insertionAnchor, insertionParent } from './insertionState'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
|
|
||||||
export function createIf(
|
export function createIf(
|
||||||
|
@ -6,13 +8,24 @@ export function createIf(
|
||||||
b1: BlockFn,
|
b1: BlockFn,
|
||||||
b2?: BlockFn,
|
b2?: BlockFn,
|
||||||
once?: boolean,
|
once?: boolean,
|
||||||
// hydrationNode?: Node,
|
|
||||||
): Block {
|
): Block {
|
||||||
if (once) {
|
const _insertionParent = insertionParent
|
||||||
return condition() ? b1() : b2 ? b2() : []
|
const _insertionAnchor = insertionAnchor
|
||||||
} else {
|
if (isHydrating) {
|
||||||
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
|
locateHydrationNode()
|
||||||
renderEffect(() => frag.update(condition() ? b1 : b2))
|
|
||||||
return frag
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let frag: Block
|
||||||
|
if (once) {
|
||||||
|
frag = condition() ? b1() : b2 ? b2() : []
|
||||||
|
} else {
|
||||||
|
frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
|
||||||
|
renderEffect(() => (frag as DynamicFragment).update(condition() ? b1 : b2))
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isHydrating && _insertionParent) {
|
||||||
|
insert(frag, _insertionParent, _insertionAnchor)
|
||||||
|
}
|
||||||
|
|
||||||
|
return frag
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
|
import { EMPTY_OBJ, NO, hasOwn, isArray, isFunction } from '@vue/shared'
|
||||||
import { type Block, type BlockFn, DynamicFragment } from './block'
|
import { type Block, type BlockFn, DynamicFragment, insert } from './block'
|
||||||
import { rawPropsProxyHandlers } from './componentProps'
|
import { rawPropsProxyHandlers } from './componentProps'
|
||||||
import { currentInstance, isRef } from '@vue/runtime-dom'
|
import { currentInstance, isRef } from '@vue/runtime-dom'
|
||||||
import type { LooseRawProps, VaporComponentInstance } from './component'
|
import type { LooseRawProps, VaporComponentInstance } from './component'
|
||||||
import { renderEffect } from './renderEffect'
|
import { renderEffect } from './renderEffect'
|
||||||
|
import { insertionAnchor, insertionParent } from './insertionState'
|
||||||
|
import { isHydrating, locateHydrationNode } from './dom/hydration'
|
||||||
|
|
||||||
export type RawSlots = Record<string, VaporSlot> & {
|
export type RawSlots = Record<string, VaporSlot> & {
|
||||||
$?: DynamicSlotSource[]
|
$?: DynamicSlotSource[]
|
||||||
|
@ -90,6 +92,12 @@ export function createSlot(
|
||||||
rawProps?: LooseRawProps | null,
|
rawProps?: LooseRawProps | null,
|
||||||
fallback?: VaporSlot,
|
fallback?: VaporSlot,
|
||||||
): Block {
|
): Block {
|
||||||
|
const _insertionParent = insertionParent
|
||||||
|
const _insertionAnchor = insertionAnchor
|
||||||
|
if (isHydrating) {
|
||||||
|
locateHydrationNode()
|
||||||
|
}
|
||||||
|
|
||||||
const instance = currentInstance as VaporComponentInstance
|
const instance = currentInstance as VaporComponentInstance
|
||||||
const rawSlots = instance.rawSlots
|
const rawSlots = instance.rawSlots
|
||||||
const slotProps = rawProps
|
const slotProps = rawProps
|
||||||
|
@ -135,5 +143,9 @@ export function createSlot(
|
||||||
renderSlot()
|
renderSlot()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!isHydrating && _insertionParent) {
|
||||||
|
insert(fragment, _insertionParent, _insertionAnchor)
|
||||||
|
}
|
||||||
|
|
||||||
return fragment
|
return fragment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue