findCompNearest<C extends Comp<T>> method

C? findCompNearest<C extends Comp<T>>()

Finds the closest component of type C via breadth-first search.

Implementation

C? findCompNearest<C extends Comp<T>>() {
  // check self first
  final self = get<C>();
  if (self != null) return self;

  // check parent chain
  final inParent = findCompInParent<C>();
  if (inParent != null) return inParent;

  // check children
  return findComp<C>();
}