wip: save

This commit is contained in:
daiwei 2025-03-21 17:47:43 +08:00
parent b945079643
commit dd18528023
1 changed files with 33 additions and 10 deletions

View File

@ -35,10 +35,17 @@ export const VaporTeleportImpl = {
rawPropsProxyHandlers, rawPropsProxyHandlers,
) as any as TeleportProps ) as any as TeleportProps
let children: Block
renderEffect(() => {
frag.updateChildren(
(children = slots.default && (slots.default as BlockFn)()),
)
})
renderEffect(() => { renderEffect(() => {
const children = slots.default && (slots.default as BlockFn)()
// access the props to trigger tracking // access the props to trigger tracking
frag.update(extend({}, resolvedProps), children) frag.update(extend({}, resolvedProps), children!)
}) })
return frag return frag
@ -50,7 +57,8 @@ export class TeleportFragment extends VaporFragment {
targetStart?: Node | null targetStart?: Node | null
mainAnchor?: Node mainAnchor?: Node
placeholder?: Node placeholder?: Node
currentParent?: ParentNode | null container?: ParentNode | null
currentAnchor?: Node | null
constructor(anchorLabel?: string) { constructor(anchorLabel?: string) {
super([]) super([])
@ -58,18 +66,33 @@ export class TeleportFragment extends VaporFragment {
__DEV__ && anchorLabel ? createComment(anchorLabel) : createTextNode() __DEV__ && anchorLabel ? createComment(anchorLabel) : createTextNode()
} }
update(props: TeleportProps, children: Block): void { updateChildren(children: Block): void {
const parent = this.anchor.parentNode const parent = this.anchor.parentNode
if (!parent) return
const container = this.container || parent
// teardown previous // teardown previous
if (this.nodes && (this.currentParent || parent)) { remove(this.nodes, container)
remove(this.nodes, (this.currentParent || parent)!)
insert(
(this.nodes = children),
container,
this.currentAnchor || this.anchor,
)
} }
update(props: TeleportProps, children: Block): void {
const parent = this.anchor.parentNode
this.nodes = children this.nodes = children
const disabled = isTeleportDisabled(props) const disabled = isTeleportDisabled(props)
const mount = (parent: ParentNode, anchor: Node | null) => { const mount = (parent: ParentNode, anchor: Node | null) => {
insert(this.nodes, (this.currentParent = parent), anchor) insert(
this.nodes,
(this.container = parent),
(this.currentAnchor = anchor),
)
} }
const mountToTarget = () => { const mountToTarget = () => {
@ -124,7 +147,7 @@ export class TeleportFragment extends VaporFragment {
remove = (parent: ParentNode | undefined): void => { remove = (parent: ParentNode | undefined): void => {
// remove nodes // remove nodes
remove(this.nodes, this.currentParent || parent) remove(this.nodes, this.container || parent)
// remove anchors // remove anchors
if (this.targetStart) { if (this.targetStart) {