vue3-core/packages/runtime-vapor/src/apiCreateIf.ts

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

19 lines
468 B
TypeScript
Raw Normal View History

2024-12-14 20:37:43 +08:00
import { type BlockFn, DynamicFragment } from './block'
import { renderEffect } from './renderEffect'
2024-12-11 11:50:17 +08:00
export function createIf(
condition: () => any,
b1: BlockFn,
b2?: BlockFn,
once?: boolean,
// hydrationNode?: Node,
2024-12-14 20:37:43 +08:00
): DynamicFragment {
const frag = __DEV__ ? new DynamicFragment('if') : new DynamicFragment()
if (once) {
frag.update(condition() ? b1 : b2)
} else {
renderEffect(() => frag.update(condition() ? b1 : b2))
}
return frag
2024-12-11 11:50:17 +08:00
}