Skip to content

Commit 8957eaa

Browse files
committed
wip: handle in-out mode
1 parent a8140ac commit 8957eaa

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

packages/runtime-vapor/src/block.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export type Block = (
2323
TransitionBlock
2424

2525
export type TransitionBlock = {
26+
key?: any
2627
transition?: TransitionHooks
2728
applyLeavingHooks?: (
2829
block: Block,
@@ -91,11 +92,14 @@ export class DynamicFragment extends VaporFragment {
9192
// teardown previous branch
9293
if (this.scope) {
9394
this.scope.stop()
94-
if (this.transition && this.transition.mode) {
95+
const mode = this.transition && this.transition.mode
96+
if (mode) {
9597
const transition = this.applyLeavingHooks!(this.nodes, renderNewBranch)
9698
parent && remove(this.nodes, parent, transition)
97-
resetTracking()
98-
return
99+
if (mode === 'out-in') {
100+
resetTracking()
101+
return
102+
}
99103
} else {
100104
parent && remove(this.nodes, parent, this.transition)
101105
}

packages/runtime-vapor/src/components/Transition.ts

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,17 @@ export const vaporTransitionImpl: VaporTransitionInterface = {
4141
const { mode } = props
4242
// TODO check mode
4343

44-
child.applyLeavingHooks = (block: Block, afterLeaveCb: () => void) => {
44+
child.applyLeavingHooks = (
45+
leavingBlock: Block,
46+
afterLeaveCb: () => void,
47+
) => {
4548
let leavingHooks = resolveTransitionHooks(
46-
block as any,
49+
leavingBlock as any,
4750
props,
4851
state,
4952
currentInstance!,
5053
)
51-
setTransitionHooks(block, leavingHooks)
54+
setTransitionHooks(leavingBlock, leavingHooks)
5255

5356
if (mode === 'out-in') {
5457
state.isLeaving = true
@@ -58,8 +61,23 @@ export const vaporTransitionImpl: VaporTransitionInterface = {
5861
delete leavingHooks.afterLeave
5962
}
6063
} else if (mode === 'in-out') {
61-
leavingHooks.delayLeave = (block: Block, earlyRemove, delayedLeave) => {
62-
// TODO delay leave
64+
leavingHooks.delayLeave = (
65+
block: TransitionElement,
66+
earlyRemove,
67+
delayedLeave,
68+
) => {
69+
const leavingNodeCache = getLeavingNodesForBlock(state, leavingBlock)
70+
leavingNodeCache[String(leavingBlock.key)] = leavingBlock
71+
// early removal callback
72+
block[leaveCbKey] = () => {
73+
earlyRemove()
74+
block[leaveCbKey] = undefined
75+
delete enterHooks.delayedLeave
76+
}
77+
enterHooks.delayedLeave = () => {
78+
delayedLeave()
79+
delete enterHooks.delayedLeave
80+
}
6381
}
6482
}
6583
return leavingHooks
@@ -70,7 +88,7 @@ export const vaporTransitionImpl: VaporTransitionInterface = {
7088
}
7189

7290
function resolveTransitionHooks(
73-
block: Block & { key: string },
91+
block: Block,
7492
props: TransitionProps,
7593
state: TransitionState,
7694
instance: GenericComponentInstance,

0 commit comments

Comments
 (0)