link method

Link? link(
  1. Dependency dep,
  2. Subscriber sub
)

Links a given dependency and subscriber if they are not already linked.

dep - The dependency to be linked. sub - The subscriber that depends on this dependency. Returns the newly created link object if the two are not already linked; otherwise null.

Implementation

Link? link(Dependency dep, Subscriber sub) {
  final currentDep = sub.depsTail;
  if (currentDep != null && currentDep.dep == dep) {
    return null;
  }
  final nextDep = currentDep != null ? currentDep.nextDep : sub.deps;
  if (nextDep != null && nextDep.dep == dep) {
    sub.depsTail = nextDep;
    return null;
  }
  final depLastSub = dep.subsTail;
  if (depLastSub != null &&
      depLastSub.sub == sub &&
      isValidLink(depLastSub, sub)) {
    return null;
  }

  return linkNewDep(dep, sub, nextDep, currentDep);
}