提交 c7e4fa0c 编写于 作者: Q qiang

fix: Remove UniNode Children

# Conflicts:
#	packages/uni-app-plus/dist/uni-app-view.umd.js
上级 66e6b3c9
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -140,9 +140,11 @@ export class UniComponent extends UniNode {
}
remove() {
this.removeUniParent()
this.isUnmounted = true
this.$app.unmount()
removeElement(this.id)
this.removeUniChildren()
}
appendChild(node: Element) {
return (this.$holder || this.$).appendChild(node)
......
import { hasOwn } from '@vue/shared'
import { ATTR_CHANGE_PREFIX, UniNodeJSON } from '@dcloudio/uni-shared'
import { $, removeElement } from '../page'
import { $, getElement, removeElement } from '../page'
import { JOB_PRIORITY_WXS_PROPS, queuePostActionJob } from '../scheduler'
import { createWxsPropsInvoker, WxsPropsInvoker } from '../wxs'
import { destroyRenderjs } from '../renderjs'
......@@ -16,6 +16,8 @@ export class UniNode {
isUnmounted: boolean = false
$wxsProps: Map<string, WxsPropsInvoker>
$hasWxsProps: boolean = false
$parent: UniNode | undefined
$children: UniNode[] = []
constructor(
id: number,
tag: string,
......@@ -29,6 +31,10 @@ export class UniNode {
this.$ = element
}
this.$wxsProps = new Map<string, WxsPropsInvoker>()
const parent = (this.$parent = getElement(parentNodeId))
if (parent) {
parent.appendUniChild(this)
}
}
init(nodeJson: Partial<UniNodeJSON>) {
if (hasOwn(nodeJson, 't')) {
......@@ -49,11 +55,13 @@ export class UniNode {
this.isMounted = true
}
remove() {
this.removeUniParent()
const { $ } = this
$.parentNode!.removeChild($)
this.isUnmounted = true
removeElement(this.id)
destroyRenderjs(this)
this.removeUniChildren()
}
appendChild(node: Node) {
return this.$.appendChild(node)
......@@ -61,6 +69,26 @@ export class UniNode {
insertBefore(newChild: Node, refChild: Node) {
return this.$.insertBefore(newChild, refChild)
}
appendUniChild(node: UniNode) {
this.$children.push(node)
}
removeUniChild(node: UniNode) {
const index = this.$children.indexOf(node)
if (index >= 0) {
this.$children.splice(index, 1)
}
}
removeUniParent() {
const { $parent } = this
if ($parent) {
$parent.removeUniChild(this)
this.$parent = undefined
}
}
removeUniChildren() {
this.$children.forEach((node) => node.remove())
this.$children.length = 0
}
setWxsProps(attrs: Record<string, any>) {
Object.keys(attrs).forEach((name) => {
if (name.indexOf(ATTR_CHANGE_PREFIX) === 0) {
......
......@@ -23,6 +23,10 @@ export function $(id: number) {
return elements.get(id) as UniElement<any>
}
export function getElement(id: number) {
return elements.get(id)
}
export function removeElement(id: number) {
if (__DEV__) {
console.log(formatLog('Remove', id, elements.size - 1))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册