onCleanUp method

void onCleanUp(
  1. Disposer fn
)

Registers a cleanup function to be called when this effect is disposed or re-run.

Parameters:

  • fn: The cleanup function to register

Cleanup functions are executed in the order they were registered, either when the effect is disposed or before the effect function is re-run.

Example:

final effect = Effect(() {
  final subscription = someStream.listen((data) {});
  onEffectCleanup(() => subscription.cancel());
});

Implementation

void onCleanUp(Disposer fn) {
  assert(!isDisposed, "$runtimeType is disposed");

  _cleanups.add(fn);
}