liveBook · Manning

hFragment function

As explained in Build a Frontend Web Framework (From Scratch)

A JavaScript function that creates fragment virtual nodes from an array of child nodes.

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:

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

How Build a Frontend Web Framework (From Scratch) covers it

How deep it goes
Defines a compact implementation that removes null children and converts strings to text nodes, without detailing helper internals.
Examples
Uses a login-form virtual DOM and proposes lipsum() for generating a fragment of placeholder paragraphs.
What it assumes
Assumes virtual-node construction and distinguishes fragments from text and element nodes.
What you can do after
Builds fragment virtual nodes from child arrays and uses them when composing component views.
How it connects
Connects fragments with virtual DOM trees, text nodes, element nodes, components, and DOM rendering.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Frontend Web Framework (From Scratch). The section links point to the parts of the book it draws on.