hFragment() creates a fragment virtual node from an array of child nodes. The fragment groups siblings without adding a parent element, allowing a component to return a list of virtual nodes. Its implementation removes null children and converts string children into text virtual nodes. section 3.7.1 section 3.9
The function performs three small responsibilities:
- Marks the result as a fragment with DOM_TYPES.FRAGMENT. section 3.7.1
- Filters null values from the child array. section 3.7.1
- Maps string children to text virtual nodes while preserving other virtual nodes. section 3.7.1 section 3.6
export function hFragment(vNodes) {
return {
type: DOM_TYPES.FRAGMENT,
children: mapTextNodes(withoutNulls(vNodes)),
}
}
The compact implementation shows how fragment creation delegates child cleanup and text conversion to reusable helpers. section 3.7.1
Generated placeholder paragraphs
A lipsum(count) function can return a fragment containing count paragraphs, giving a UI temporary content without introducing an unnecessary parent node. section 3.7.2
