test: update fragment tests
This commit is contained in:
@@ -694,7 +694,9 @@ export function createRenderer(options: RendererOptions) {
|
||||
if (prevShapeFlag & ShapeFlags.ARRAY_CHILDREN) {
|
||||
unmountChildren(c1 as VNode[], parentComponent)
|
||||
}
|
||||
hostSetElementText(container, c2 as string)
|
||||
if (c2 !== c1) {
|
||||
hostSetElementText(container, c2 as string)
|
||||
}
|
||||
} else {
|
||||
if (prevShapeFlag & ShapeFlags.TEXT_CHILDREN) {
|
||||
hostSetElementText(container, '')
|
||||
|
||||
49
packages/runtime-core/src/h.ts
Normal file
49
packages/runtime-core/src/h.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { VNodeTypes, VNode, createVNode } from './vnode'
|
||||
import { isObject, isArray } from '@vue/shared'
|
||||
|
||||
// `h` is a more user-friendly version of `createVNode` that allows omitting the
|
||||
// props when possible. It is intended for manually written render functions.
|
||||
// Compiler-generated code uses `createVNode` because
|
||||
// 1. it is monomorphic and avoids the extra call overhead
|
||||
// 2. it allows specifying patchFlags for optimization
|
||||
|
||||
/*
|
||||
// type only
|
||||
h('div')
|
||||
|
||||
// type + props
|
||||
h('div', {})
|
||||
|
||||
// type + omit props + children
|
||||
// Omit props does NOT support named slots
|
||||
h('div', []) // array
|
||||
h('div', () => {}) // default slot
|
||||
h('div', 'foo') // text
|
||||
|
||||
// type + props + children
|
||||
h('div', {}, []) // array
|
||||
h('div', {}, () => {}) // default slot
|
||||
h('div', {}, {}) // named slots
|
||||
h('div', {}, 'foo') // text
|
||||
|
||||
// named slots without props requires explicit `null` to avoid ambiguity
|
||||
h('div', null, {})
|
||||
**/
|
||||
|
||||
export function h(
|
||||
type: VNodeTypes,
|
||||
propsOrChildren?: any,
|
||||
children?: any
|
||||
): VNode {
|
||||
if (arguments.length === 2) {
|
||||
if (isObject(propsOrChildren) && !isArray(propsOrChildren)) {
|
||||
// props without children
|
||||
return createVNode(type, propsOrChildren)
|
||||
} else {
|
||||
// omit props
|
||||
return createVNode(type, null, propsOrChildren)
|
||||
}
|
||||
} else {
|
||||
return createVNode(type, propsOrChildren, children)
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ export * from './apiInject'
|
||||
// Advanced API ----------------------------------------------------------------
|
||||
|
||||
// For raw render function users
|
||||
export { h } from './h'
|
||||
export {
|
||||
createVNode,
|
||||
cloneVNode,
|
||||
|
||||
@@ -18,7 +18,7 @@ export const Text = Symbol('Text')
|
||||
export const Empty = Symbol('Empty')
|
||||
export const Portal = Symbol('Portal')
|
||||
|
||||
type VNodeTypes =
|
||||
export type VNodeTypes =
|
||||
| string
|
||||
| Function
|
||||
| Object
|
||||
|
||||
Reference in New Issue
Block a user