mirror of https://github.com/vuejs/core.git
wip: vapor app.unmount + unmounted hooks
This commit is contained in:
parent
ac5f1cfe3f
commit
366dcb7c76
|
@ -1,5 +1,10 @@
|
||||||
import { insert } from './dom/node'
|
import {
|
||||||
import { type VaporComponent, createComponent } from './component'
|
type VaporComponent,
|
||||||
|
type VaporComponentInstance,
|
||||||
|
createComponent,
|
||||||
|
mountComponent,
|
||||||
|
unmountComponent,
|
||||||
|
} from './component'
|
||||||
import {
|
import {
|
||||||
type AppMountFn,
|
type AppMountFn,
|
||||||
type AppUnmountFn,
|
type AppUnmountFn,
|
||||||
|
@ -17,12 +22,12 @@ const mountApp: AppMountFn<ParentNode> = (app, container) => {
|
||||||
container.textContent = ''
|
container.textContent = ''
|
||||||
}
|
}
|
||||||
const instance = createComponent(app._component, app._props as RawProps)
|
const instance = createComponent(app._component, app._props as RawProps)
|
||||||
insert(instance, container)
|
mountComponent(instance, container)
|
||||||
return instance
|
return instance
|
||||||
}
|
}
|
||||||
|
|
||||||
const unmountApp: AppUnmountFn = app => {
|
const unmountApp: AppUnmountFn = app => {
|
||||||
// TODO
|
unmountComponent(app._instance as VaporComponentInstance, app._container)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createVaporApp: CreateAppFunction<
|
export const createVaporApp: CreateAppFunction<
|
||||||
|
|
|
@ -399,12 +399,12 @@ export function createComponentWithFallback(
|
||||||
export function mountComponent(
|
export function mountComponent(
|
||||||
instance: VaporComponentInstance,
|
instance: VaporComponentInstance,
|
||||||
parent: ParentNode,
|
parent: ParentNode,
|
||||||
anchor: Node | null | 0,
|
anchor?: Node | null | 0,
|
||||||
): void {
|
): void {
|
||||||
if (!instance.isMounted) {
|
if (!instance.isMounted) {
|
||||||
if (instance.bm) invokeArrayFns(instance.bm)
|
if (instance.bm) invokeArrayFns(instance.bm)
|
||||||
insert(instance.block, parent, anchor)
|
insert(instance.block, parent, anchor)
|
||||||
// queuePostFlushCb(() => {
|
// TODO queuePostFlushCb(() => {
|
||||||
if (instance.m) invokeArrayFns(instance.m)
|
if (instance.m) invokeArrayFns(instance.m)
|
||||||
instance.isMounted = true
|
instance.isMounted = true
|
||||||
// })
|
// })
|
||||||
|
@ -415,7 +415,7 @@ export function mountComponent(
|
||||||
|
|
||||||
export function unmountComponent(
|
export function unmountComponent(
|
||||||
instance: VaporComponentInstance,
|
instance: VaporComponentInstance,
|
||||||
parent: ParentNode,
|
parent?: ParentNode,
|
||||||
): void {
|
): void {
|
||||||
if (instance.isMounted && !instance.isUnmounted) {
|
if (instance.isMounted && !instance.isUnmounted) {
|
||||||
if (__DEV__ && instance.type.__hmrId) {
|
if (__DEV__ && instance.type.__hmrId) {
|
||||||
|
@ -423,11 +423,15 @@ export function unmountComponent(
|
||||||
}
|
}
|
||||||
if (instance.bum) invokeArrayFns(instance.bum)
|
if (instance.bum) invokeArrayFns(instance.bum)
|
||||||
instance.scope.stop()
|
instance.scope.stop()
|
||||||
// TODO invoke unmount recursively for children
|
for (const c of instance.children) {
|
||||||
remove(instance.block, parent)
|
unmountComponent(c)
|
||||||
// queuePostFlushCb(() => {
|
}
|
||||||
|
if (parent) remove(instance.block, parent)
|
||||||
|
// TODO queuePostFlushCb(() => {
|
||||||
if (instance.um) invokeArrayFns(instance.um)
|
if (instance.um) invokeArrayFns(instance.um)
|
||||||
instance.isUnmounted = true
|
instance.isUnmounted = true
|
||||||
// })
|
// })
|
||||||
|
} else if (parent) {
|
||||||
|
remove(instance.block, parent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue