Skip to content

Commit 087c10f

Browse files
committed
refactor(Teleport): extract inline mount and mountToTarget functions into class methods
1 parent c9f9b85 commit 087c10f

File tree

1 file changed

+49
-49
lines changed

1 file changed

+49
-49
lines changed

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

Lines changed: 49 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -142,59 +142,59 @@ export class TeleportFragment extends VaporFragment<Block[]> {
142142
insert((this.nodes = [children]), this.mountContainer!, this.mountAnchor!)
143143
}
144144

145-
private handlePropsUpdate(): void {
146-
// not mounted yet
147-
if (!this.parent || isHydrating) return
148-
149-
const mount = (parent: ParentNode, anchor: Node | null) => {
150-
if (this.$transition) {
151-
applyTransitionHooks(this.nodes, this.$transition)
152-
}
153-
insert(
154-
this.nodes,
155-
(this.mountContainer = parent),
156-
(this.mountAnchor = anchor),
157-
)
145+
private mount(parent: ParentNode, anchor: Node | null): void {
146+
if (this.$transition) {
147+
applyTransitionHooks(this.nodes, this.$transition)
158148
}
149+
insert(
150+
this.nodes,
151+
(this.mountContainer = parent),
152+
(this.mountAnchor = anchor),
153+
)
154+
}
159155

160-
const mountToTarget = () => {
161-
const target = (this.target = resolveTeleportTarget(
162-
this.resolvedProps!,
163-
querySelector,
164-
))
165-
if (target) {
166-
if (
167-
// initial mount into target
168-
!this.targetAnchor ||
169-
// target changed
170-
this.targetAnchor.parentNode !== target
171-
) {
172-
insert((this.targetStart = createTextNode('')), target)
173-
insert((this.targetAnchor = createTextNode('')), target)
174-
}
175-
176-
// track CE teleport targets
177-
if (this.parentComponent && this.parentComponent.isCE) {
178-
;(
179-
this.parentComponent.ce!._teleportTargets ||
180-
(this.parentComponent.ce!._teleportTargets = new Set())
181-
).add(target)
182-
}
156+
private mountToTarget = (): void => {
157+
const target = (this.target = resolveTeleportTarget(
158+
this.resolvedProps!,
159+
querySelector,
160+
))
161+
if (target) {
162+
if (
163+
// initial mount into target
164+
!this.targetAnchor ||
165+
// target changed
166+
this.targetAnchor.parentNode !== target
167+
) {
168+
insert((this.targetStart = createTextNode('')), target)
169+
insert((this.targetAnchor = createTextNode('')), target)
170+
}
183171

184-
mount(target, this.targetAnchor!)
185-
updateCssVars(this)
186-
} else if (__DEV__) {
187-
warn(
188-
`Invalid Teleport target on ${this.targetAnchor ? 'update' : 'mount'}:`,
189-
target,
190-
`(${typeof target})`,
191-
)
172+
// track CE teleport targets
173+
if (this.parentComponent && this.parentComponent.isCE) {
174+
;(
175+
this.parentComponent.ce!._teleportTargets ||
176+
(this.parentComponent.ce!._teleportTargets = new Set())
177+
).add(target)
192178
}
179+
180+
this.mount(target, this.targetAnchor!)
181+
updateCssVars(this)
182+
} else if (__DEV__) {
183+
warn(
184+
`Invalid Teleport target on ${this.targetAnchor ? 'update' : 'mount'}:`,
185+
target,
186+
`(${typeof target})`,
187+
)
193188
}
189+
}
190+
191+
private handlePropsUpdate(): void {
192+
// not mounted yet
193+
if (!this.parent || isHydrating) return
194194

195195
// mount into main container
196196
if (this.isDisabled) {
197-
mount(this.parent, this.anchor!)
197+
this.mount(this.parent, this.anchor!)
198198
updateCssVars(this)
199199
}
200200
// mount into target container
@@ -205,9 +205,9 @@ export class TeleportFragment extends VaporFragment<Block[]> {
205205
// typically due to an early insertion caused by setInsertionState.
206206
!this.parent!.isConnected
207207
) {
208-
queuePostFlushCb(mountToTarget)
208+
queuePostFlushCb(this.mountToTarget)
209209
} else {
210-
mountToTarget()
210+
this.mountToTarget()
211211
}
212212
}
213213
}
@@ -263,7 +263,7 @@ export class TeleportFragment extends VaporFragment<Block[]> {
263263
this.initChildren()
264264
}
265265

266-
private mount(target: Node): void {
266+
private mountChildren(target: Node): void {
267267
target.appendChild((this.targetStart = createTextNode('')))
268268
target.appendChild(
269269
(this.mountAnchor = this.targetAnchor = createTextNode('')),
@@ -322,7 +322,7 @@ export class TeleportFragment extends VaporFragment<Block[]> {
322322
// always be null, we need to manually add targetAnchor to ensure
323323
// Teleport it can properly unmount or move
324324
if (!this.targetAnchor) {
325-
this.mount(target)
325+
this.mountChildren(target)
326326
} else {
327327
this.initChildren()
328328
}

0 commit comments

Comments
 (0)