mount method
Implementation
void mount(Component root) {
if (_mounted) {
throw StateError('ComponentRuntime is already mounted');
}
rootComponent = root;
root.attach(this);
RenderContext.run(this, () {
// Phase 1 — resolve the Morphic tree.
// resolveNode returns a typed ResolveResult — success or failure is
// explicit, never hidden in exception propagation.
final result = resolveNode(ComponentRenderNode(root));
switch (result) {
case ResolveSuccess(:final tree, :final owners):
_currentTree = tree;
_componentTrees[root] = tree;
// Phase 2 — create the real DOM.
// owners is passed explicitly so createDom can register each
// component's root DOM node without touching shared mutable state.
final dom = createDom(tree, componentOwner: root, owners: owners);
_componentNodes[root] = dom;
renderer.mount(tree);
_mounted = true;
case ResolveFailure(
:final error,
:final stackTrace,
:final failedComponent,
):
throw StateError(
'Failed to mount '
'${failedComponent?.runtimeType ?? root.runtimeType}: '
'$error\n$stackTrace',
);
}
});
}