mount function

BloomMountHandle mount(
  1. BloomNode node,
  2. String selector
)

Mounts a BloomNode descriptor tree into the DOM element matching selector.

Looks up the host element via web.document.querySelector(selector) and delegates to mountToElement. Throws a StateError if selector matches no element in the document.

The caller owns the returned BloomMountHandle and should call BloomMountHandle.unmount when the application is detached.

void main() {
  final handle = mount(
    Div(
      className: 'container',
      children: [
        const H1(text: 'Bloom Web App'),
        Live(() => P(text: 'Current count: ${count.value}')),
      ],
    ),
    '#app',
  );
}

Implementation

BloomMountHandle mount(BloomNode node, String selector) {
  final root = web.document.querySelector(selector);
  if (root == null) {
    throw StateError('Bloom mount: selector "$selector" matched no element.');
  }
  return mountToElement(node, root);
}