register<T> abstract method

T register<T>(
  1. SideEffect<T> sideEffect
)

Registers the given side effect and serves as the underlying base of all side effects.

"Registering a side effect" involves invoking sideEffect only on the first build, followed by returning the return value of sideEffect on the first and all subsequent builds.

Thus, if you write:

final (getCount, incrementCount) = use.register((api) {
  int count = 0;
  return (
    getCount: () => count,
    incrementCount: () => count++;
  );
})

You will get the same copy of (getCount, incrementCount) on every build, which is why we have to return getCount instead of count directly (otherwise, it would never get updates).

Implementation

T register<T>(SideEffect<T> sideEffect);