removeChild method

  1. @mustCallSuper
Node removeChild(
  1. Node child
)

Implementation

@mustCallSuper
Node removeChild(Node child) {

  // Not remove node type which is not present in RenderObject tree such as Comment
  // Only append node types which is visible in RenderObject tree
  // Only remove childNode when it has parent
  if (child.isRendererAttached) {
    child.unmountRenderObject();
  }

  if (childNodes.contains(child)) {
    bool isConnected = child.isConnected;
    childNodes.remove(child);
    child.parentNode = null;

    // To remove a node, run step 21 from the spec:
    // 21. Run the children changed steps for parent.
    // https://dom.spec.whatwg.org/#concept-node-remove
    childrenChanged();

    if (isConnected) {
      child.disconnectedCallback();
    }
  }
  return child;
}