unlink method

Link? unlink(
  1. Link link,
  2. ReactiveNode sub
)

Removes a dependency link from the graph.

Disconnects the relationship represented by link, removing it from both the dependency's subscriber list and the subscriber's dependency list.

If the dependency node has no remaining subscribers after unlinking, unwatched is called to handle cleanup.

Returns the next link in the subscriber's dependency list, or null if this was the last dependency.

Implementation

Link? unlink(final Link link, final ReactiveNode sub) {
  final dep = link.dep,
      prevDep = link.prevDep,
      nextDep = link.nextDep,
      nextSub = link.nextSub,
      prevSub = link.prevSub;
  if (nextDep != null) {
    nextDep.prevDep = prevDep;
  } else {
    sub.depsTail = prevDep;
  }
  if (prevDep != null) {
    prevDep.nextDep = nextDep;
  } else {
    sub.deps = nextDep;
  }
  if (nextSub != null) {
    nextSub.prevSub = prevSub;
  } else {
    dep.subsTail = prevSub;
  }
  if (prevSub != null) {
    prevSub.nextSub = nextSub;
  } else if ((dep.subs = nextSub) == null) {
    unwatched(dep);
  }
  return nextDep;
}