link method

  1. @override
Linkable link(
  1. Controller instantiator()
)
override

Links a controller to the receiver to form a request channel.

Establishes a channel containing the receiver and the controller returned by instantiator. If the receiver does not handle a request, the controller created by instantiator will get an opportunity to do so.

instantiator is called immediately when invoking this function. If the returned Controller does not implement Recyclable, this is the only time instantiator is called. The returned controller must only have properties that are marked as final.

If the returned controller has properties that are not marked as final, it must implement Recyclable. When a controller implements Recyclable, instantiator is called for each new request that reaches this point of the channel. See Recyclable for more details.

See linkFunction for a variant of this method that takes a closure instead of an object.

Implementation

@override
Linkable link(Controller instantiator()) {
  final instance = instantiator();
  if (instance is Recyclable) {
    _nextController = _ControllerRecycler(instantiator, instance);
  } else {
    _nextController = instantiator();
  }

  return _nextController!;
}