优化代码, 减少体积

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", "name": "wkitd",
"version": "1.3.11", "version": "1.3.12",
"type": "module", "type": "module",
"main": "dist/index.js", "main": "dist/index.js",
"files": [ "files": [

View File

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