Skip to content

Commit 75de3bb

Browse files
committed
wip: save
1 parent 1e79054 commit 75de3bb

File tree

3 files changed

+36
-74
lines changed

3 files changed

+36
-74
lines changed

packages/runtime-core/src/components/BaseTransition.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export interface TransitionState {
8888
isUnmounting: boolean
8989
// Track pending leave callbacks for children of the same key.
9090
// This is used to force remove leaving a child when a new copy is entering.
91-
leavingVNodes: Map<any, Record<string, any>>
91+
leavingNodes: Map<any, Record<string, any>>
9292
}
9393

9494
export interface TransitionElement {
@@ -104,7 +104,7 @@ export function useTransitionState(): TransitionState {
104104
isMounted: false,
105105
isLeaving: false,
106106
isUnmounting: false,
107-
leavingVNodes: new Map(),
107+
leavingNodes: new Map(),
108108
}
109109
onMounted(() => {
110110
state.isMounted = true
@@ -310,11 +310,11 @@ function getLeavingNodesForType(
310310
state: TransitionState,
311311
vnode: VNode,
312312
): Record<string, VNode> {
313-
const { leavingVNodes } = state
314-
let leavingVNodesCache = leavingVNodes.get(vnode.type)!
313+
const { leavingNodes } = state
314+
let leavingVNodesCache = leavingNodes.get(vnode.type)!
315315
if (!leavingVNodesCache) {
316316
leavingVNodesCache = Object.create(null)
317-
leavingVNodes.set(vnode.type, leavingVNodesCache)
317+
leavingNodes.set(vnode.type, leavingVNodesCache)
318318
}
319319
return leavingVNodesCache
320320
}

packages/runtime-vapor/src/block.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ export type Block = (
2929
TransitionBlock
3030

3131
export interface VaporTransitionHooks extends TransitionHooks {
32-
state?: TransitionState
33-
props?: TransitionProps
32+
state: TransitionState
33+
props: TransitionProps
3434
}
3535

3636
export type TransitionBlock = {
@@ -74,16 +74,14 @@ export class DynamicFragment extends VaporFragment {
7474
pauseTracking()
7575
const parent = this.anchor.parentNode
7676

77+
const transition = this.transition
7778
const renderBranch = () => {
7879
if (render) {
79-
const transition = this.transition
8080
this.scope = new EffectScope()
8181
this.nodes = this.scope.run(render) || []
8282
if (transition) {
8383
this.transitionChild = applyTransitionEnterHooks(
8484
this.nodes,
85-
transition.state!,
86-
transition.props!,
8785
transition,
8886
)
8987
}
@@ -97,15 +95,9 @@ export class DynamicFragment extends VaporFragment {
9795
// teardown previous branch
9896
if (this.scope) {
9997
this.scope.stop()
100-
const mode = this.transition && this.transition.mode
98+
const mode = transition && transition.mode
10199
if (mode) {
102-
applyTransitionLeaveHooks(
103-
this.nodes,
104-
this.transition!.state!,
105-
this.transition!.props!,
106-
renderBranch,
107-
this.transition,
108-
)
100+
applyTransitionLeaveHooks(this.nodes, transition, renderBranch)
109101
parent && remove(this.nodes, parent)
110102
if (mode === 'out-in') {
111103
resetTracking()

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

Lines changed: 26 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,35 @@ export const vaporTransitionImpl: VaporTransitionInterface = {
3535
warn(`invalid <transition> mode: ${mode}`)
3636
}
3737

38-
applyTransitionEnterHooks(
39-
children,
40-
useTransitionState(),
38+
applyTransitionEnterHooks(children, {
39+
state: useTransitionState(),
4140
props,
42-
undefined,
43-
false,
44-
)
41+
} as VaporTransitionHooks)
4542

4643
return children
4744
},
4845
}
4946

5047
const getTransitionHooksContext = (
51-
key: string,
52-
block: Block,
48+
key: String,
5349
props: TransitionProps,
5450
state: TransitionState,
5551
instance: GenericComponentInstance,
5652
postClone: ((hooks: TransitionHooks) => void) | undefined,
5753
) => {
54+
const { leavingNodes } = state
5855
const context: TransitionHooksContext = {
5956
setLeavingNodeCache: el => {
60-
const leavingNodeCache = getLeavingNodesForBlock(state, block)
61-
leavingNodeCache[key] = el
57+
leavingNodes.set(key, el)
6258
},
6359
unsetLeavingNodeCache: el => {
64-
const leavingNodeCache = getLeavingNodesForBlock(state, block)
65-
if (leavingNodeCache[key] === el) {
66-
delete leavingNodeCache[key]
60+
const leavingNode = leavingNodes.get(key)
61+
if (leavingNode === el) {
62+
leavingNodes.delete(key)
6763
}
6864
},
6965
earlyRemove: () => {
70-
const leavingNodeCache = getLeavingNodesForBlock(state, block)
71-
const leavingNode = leavingNodeCache[key]
66+
const leavingNode = leavingNodes.get(key)
7267
if (leavingNode && (leavingNode as TransitionElement)[leaveCbKey]) {
7368
// force early removal (not cancelled)
7469
;(leavingNode as TransitionElement)[leaveCbKey]!()
@@ -96,39 +91,24 @@ function resolveTransitionHooks(
9691
instance: GenericComponentInstance,
9792
postClone?: (hooks: TransitionHooks) => void,
9893
): VaporTransitionHooks {
99-
const key = String(block.key)
10094
const context = getTransitionHooksContext(
101-
key,
102-
block,
95+
String(block.key),
10396
props,
10497
state,
10598
instance,
10699
postClone,
107100
)
108-
const hooks: VaporTransitionHooks = baseResolveTransitionHooks(
101+
const hooks = baseResolveTransitionHooks(
109102
context,
110103
props,
111104
state,
112105
instance,
113-
)
106+
) as VaporTransitionHooks
114107
hooks.state = state
115108
hooks.props = props
116109
return hooks
117110
}
118111

119-
function getLeavingNodesForBlock(
120-
state: TransitionState,
121-
block: Block,
122-
): Record<string, Block> {
123-
const { leavingVNodes } = state
124-
let leavingNodesCache = leavingVNodes.get(block)!
125-
if (!leavingNodesCache) {
126-
leavingNodesCache = Object.create(null)
127-
leavingVNodes.set(block, leavingNodesCache)
128-
}
129-
return leavingNodesCache
130-
}
131-
132112
function setTransitionHooks(block: Block, hooks: VaporTransitionHooks) {
133113
if (!isFragment(block)) {
134114
block.transition = hooks
@@ -137,28 +117,20 @@ function setTransitionHooks(block: Block, hooks: VaporTransitionHooks) {
137117

138118
export function applyTransitionEnterHooks(
139119
block: Block,
140-
state: TransitionState,
141-
props: TransitionProps,
142-
enterHooks?: VaporTransitionHooks,
143-
clone: boolean = true,
120+
hooks: VaporTransitionHooks,
144121
): Block | undefined {
145122
const child = findElementChild(block)
146123
if (child) {
147-
if (!enterHooks) {
148-
enterHooks = resolveTransitionHooks(
149-
child,
150-
props,
151-
state,
152-
currentInstance!,
153-
hooks => (enterHooks = hooks),
154-
)
155-
}
156-
157-
setTransitionHooks(
124+
const { props, state, delayedLeave } = hooks
125+
let enterHooks = resolveTransitionHooks(
158126
child,
159-
clone ? enterHooks.clone(child as any) : enterHooks,
127+
props,
128+
state,
129+
currentInstance!,
130+
hooks => (enterHooks = hooks as VaporTransitionHooks),
160131
)
161-
132+
enterHooks.delayedLeave = delayedLeave
133+
setTransitionHooks(child, enterHooks)
162134
if (isFragment(block)) {
163135
block.transitionChild = child
164136
}
@@ -168,15 +140,14 @@ export function applyTransitionEnterHooks(
168140

169141
export function applyTransitionLeaveHooks(
170142
block: Block,
171-
state: TransitionState,
172-
props: TransitionProps,
143+
enterHooks: VaporTransitionHooks,
173144
afterLeaveCb: () => void,
174-
enterHooks: TransitionHooks,
175145
): void {
176146
const leavingBlock = findElementChild(block)
177147
if (!leavingBlock) return undefined
178148

179-
let leavingHooks = resolveTransitionHooks(
149+
const { props, state } = enterHooks
150+
const leavingHooks = resolveTransitionHooks(
180151
leavingBlock,
181152
props,
182153
state,
@@ -198,8 +169,7 @@ export function applyTransitionLeaveHooks(
198169
earlyRemove,
199170
delayedLeave,
200171
) => {
201-
const leavingNodeCache = getLeavingNodesForBlock(state, leavingBlock)
202-
leavingNodeCache[String(leavingBlock.key)] = leavingBlock
172+
state.leavingNodes.set(String(leavingBlock.key), leavingBlock)
203173
// early removal callback
204174
block[leaveCbKey] = () => {
205175
earlyRemove()

0 commit comments

Comments
 (0)