精简模板解析
parent
c5333cbc2a
commit
3908bf7fe6
20
src/html.js
20
src/html.js
|
@ -254,9 +254,6 @@ class TemplateInstance {
|
||||||
get parentNode() {
|
get parentNode() {
|
||||||
return this._$parent.parentNode
|
return this._$parent.parentNode
|
||||||
}
|
}
|
||||||
get _$isConnected() {
|
|
||||||
return this._$parent._$isConnected
|
|
||||||
}
|
|
||||||
|
|
||||||
#checkRef(node, walker, options) {
|
#checkRef(node, walker, options) {
|
||||||
do {
|
do {
|
||||||
|
@ -352,11 +349,8 @@ class ChildPart {
|
||||||
this._$endNode = endNode
|
this._$endNode = endNode
|
||||||
this._$parent = parent
|
this._$parent = parent
|
||||||
this.options = options
|
this.options = options
|
||||||
this.__isConnected = options.isConnected ?? true
|
|
||||||
}
|
|
||||||
get _$isConnected() {
|
|
||||||
return this._$parent?._$isConnected ?? this.__isConnected
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get parentNode() {
|
get parentNode() {
|
||||||
let parentNode = this._$startNode.parentNode
|
let parentNode = this._$startNode.parentNode
|
||||||
let parent = this._$parent
|
let parent = this._$parent
|
||||||
|
@ -479,11 +473,6 @@ class ChildPart {
|
||||||
start = node
|
start = node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setConnected(isConnected) {
|
|
||||||
if (this._$parent === void 0) {
|
|
||||||
this.__isConnected = isConnected
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// 常规属性
|
// 常规属性
|
||||||
class AttributePart {
|
class AttributePart {
|
||||||
|
@ -505,9 +494,6 @@ class AttributePart {
|
||||||
get tagName() {
|
get tagName() {
|
||||||
return this.element.tagName
|
return this.element.tagName
|
||||||
}
|
}
|
||||||
get _$isConnected() {
|
|
||||||
return this._$parent._$isConnected
|
|
||||||
}
|
|
||||||
|
|
||||||
_$setValue(value, valueIndex) {
|
_$setValue(value, valueIndex) {
|
||||||
let strings = this.strings
|
let strings = this.strings
|
||||||
|
@ -685,9 +671,7 @@ class ElementPart {
|
||||||
this._$parent = parent
|
this._$parent = parent
|
||||||
this.options = options
|
this.options = options
|
||||||
}
|
}
|
||||||
get _$isConnected() {
|
|
||||||
return this._$parent._$isConnected
|
|
||||||
}
|
|
||||||
_$setValue(value) {}
|
_$setValue(value) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -259,8 +259,6 @@ export class Component extends HTMLElement {
|
||||||
if (this.keepAlive) {
|
if (this.keepAlive) {
|
||||||
nextTick(_ => this.deactivated())
|
nextTick(_ => this.deactivated())
|
||||||
} else {
|
} else {
|
||||||
this[__children__]?.setConnected(false)
|
|
||||||
|
|
||||||
if (!document.body?.contains(this)) {
|
if (!document.body?.contains(this)) {
|
||||||
let $events = this.$events
|
let $events = this.$events
|
||||||
if ($events) {
|
if ($events) {
|
||||||
|
@ -380,7 +378,6 @@ export class Component extends HTMLElement {
|
||||||
// 初始化时不触发updated回调
|
// 初始化时不触发updated回调
|
||||||
if (this[__mounted__] === false) {
|
if (this[__mounted__] === false) {
|
||||||
this[__mounted__] = true
|
this[__mounted__] = true
|
||||||
this[__children__].setConnected(true)
|
|
||||||
if (this.$animate?.immediate) {
|
if (this.$animate?.immediate) {
|
||||||
this.$animate()
|
this.$animate()
|
||||||
}
|
}
|
||||||
|
@ -405,8 +402,7 @@ export class Component extends HTMLElement {
|
||||||
try {
|
try {
|
||||||
let ast = this.render()
|
let ast = this.render()
|
||||||
this[__children__] = render(ast, this.root, {
|
this[__children__] = render(ast, this.root, {
|
||||||
host: this,
|
host: this
|
||||||
isConnected: !this[__mounted__] && this.isConnected
|
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err)
|
console.error(err)
|
||||||
|
|
Loading…
Reference in New Issue