requestUpdateFor method

void requestUpdateFor(
  1. Component component
)

Granular update — re-renders and diffs only component's subtree.

This is the primary update path. It never touches the root tree or any sibling component. The browser only sees changes inside the single DOM node that belongs to component.

Implementation

void requestUpdateFor(Component component) {
  if (!_mounted) return;

  if (component == rootComponent) {
    _requestRootUpdate();
    return;
  }

  final domNode = _componentNodes[component];
  final prevTree = _componentTrees[component];

  // Not yet registered: component called morph() before its first
  // resolveNode pass completed. Fall back gracefully.
  if (domNode == null || prevTree == null) {
    _requestRootUpdate();
    return;
  }

  RenderContext.run(this, () {
    RenderContext.runWithComponent(component, () {
      final nextTree = resolveNode(component.render(), owner: component);

      // Diff directly against the component's own DOM node.
      // No other part of the DOM is examined or mutated.
      patch(domNode, prevTree, nextTree);

      _componentTrees[component] = nextTree;
      component.onMorph();
    });
  });
}