buildBinding method

  1. @override
void buildBinding()
override

Implementation

@override
void buildBinding() {
  _calling = component.createCalling(this);
  rootBinding = component._root?.createBinding();
  childBinding = component._child?.createBinding();

  childBinding?.attachToParent(
    this,
  );
  rootBinding?.attachToParent(
    this,
  );

  childBinding?.buildBinding();
  rootBinding?.buildBinding();

  if (rootBinding != null) {
    var _rootGateway =
        rootBinding!.visitCallingChildren(TreeVisitor<Calling>((visitor) {
      if (visitor.currentValue is GatewayCalling) {
        visitor.stop();
        return;
      }
      if (visitor.currentValue.binding.component
          is PathSegmentCallingComponentMixin) {
        visitor.stop();
        return;
      }
    }));

    assert(
        _rootGateway.result == null,
        "Not push gateway or new sub-route from root"
        "\nwhere: $_errorWhere");
  }

  if (childBinding != null) {
    var childGateway =
        childBinding!.visitCallingChildren(TreeVisitor<Calling>((visitor) {
      if (visitor.currentValue is GatewayCalling) {
        visitor.stop();
        return;
      }
    }));
    if (childGateway.result == null) {
      throw UnsupportedError("""
        if use child, must put gateway the tree
        Route child using for define sub-segments

        WHERE: $_errorWhere

        """);
    }

    _childGateway = childGateway.result as GatewayCalling;
  }

  if ((component.segment.isRoot || component.segment.isUnknown)) {
    if (component.child != null) {
      throw UnsupportedError("""
      root route of [Route] or root route of [Service]
      or unknown routes,
      Must not create any new route

      WHERE: $_errorWhere

      """);
    }
  }
}