优化代码, 减少体积

master 1.3.12
yutent 2024-12-09 11:35:37 +08:00
parent f30eac2195
commit 092aaff8b1
2 changed files with 21 additions and 16 deletions

View File

@ -1,6 +1,6 @@
{
"name": "wkitd",
"version": "1.3.11",
"version": "1.3.12",
"type": "module",
"main": "dist/index.js",
"files": [

View File

@ -21,13 +21,16 @@ class RouterView extends Component {
set current(v) {
let old = this.#current
let $refs = this.$refs
this.#current = v
if (this.keepAlive) {
if (old) {
if (this.$refs[old]) {
this.$refs[old].removed = true
this.$refs[old].deactivated()
this.$refs[old].remove()
let $old = $refs[old]
if ($old) {
$old.removed = true
$old.deactivated()
$old.remove()
} else {
this.$requestUpdate()
}
@ -35,14 +38,15 @@ class RouterView extends Component {
this.$requestUpdate()
}
if (v) {
if (this.$refs[v]) {
this.root.appendChild(this.$refs[v])
this.$refs[v].$requestUpdate()
let $new = $refs[v]
if ($new) {
this.root.appendChild($new)
$new.$requestUpdate()
if (this.transition) {
this.$refs[v].$animate()
$new.$animate()
}
this.$refs[v].removed = false
this.$refs[v].activated()
$new.removed = false
$new.activated()
} else {
this.$requestUpdate()
}
@ -72,20 +76,21 @@ class RouterView extends Component {
{ transform: 'translateX(0)', opacity: 1 }
]
}
let name = this.current
if (this.current) {
if (name) {
if (this.transition) {
return raw(
`<${this.current} ref="${this.current}" ${
`<${name} ref="${name}" ${
this.keepAlive ? 'keep-alive' : ''
} #animation="%s"></${this.current}>`,
} #animation="%s"></${name}>`,
[option]
)
}
return raw(
`<${this.current} ref="${this.current}" ${
`<${name} ref="${name}" ${
this.keepAlive ? 'keep-alive' : ''
}></${this.current}>`
}></${name}>`
)
}
}