createViewContainerAnchor method

NodeReference createViewContainerAnchor(
  1. CompileElement parent,
  2. int nodeIndex,
  3. TemplateAst ast
)

Creates a node 'anchor' to mark the insertion point for dynamically created elements.

Implementation

NodeReference createViewContainerAnchor(
  CompileElement parent,
  int nodeIndex,
  TemplateAst ast,
) {
  final renderNode = NodeReference.anchor(storage, nodeIndex);
  final parentNode = _getParentRenderNode(parent);
  if (parentNode != o.NULL_EXPR) {
    final appendAnchor = o.importExpr(DomHelpers.appendAnchor).callFn([
      parentNode,
    ]);
    _createMethod.addStmt(renderNode.toWriteStmt(appendAnchor));
  } else {
    final createAnchor = o.importExpr(DomHelpers.createAnchor).callFn([]);
    _createMethod.addStmt(renderNode.toWriteStmt(createAnchor));
  }
  return renderNode;
}