perf(vapor): optimize v-if in once mode

This commit is contained in:
Evan You 2025-02-12 08:58:22 +08:00
parent 5d1c6ca5a9
commit 222ced2875
No known key found for this signature in database
GPG Key ID: 00E9AB7A6704CE0A
1 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,4 @@
import { type BlockFn, DynamicFragment } from './block'
import { type Block, type BlockFn, DynamicFragment } from './block'
import { renderEffect } from './renderEffect'
export function createIf(
@ -7,12 +7,12 @@ export function createIf(
b2?: BlockFn,
once?: boolean,
// hydrationNode?: Node,
): DynamicFragment {
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
): Block {
if (once) {
frag.update(condition() ? b1 : b2)
return condition() ? b1() : b2 ? b2() : []
} else {
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
renderEffect(() => frag.update(condition() ? b1 : b2))
return frag
}
return frag
}