autorun function Null safety

ReactionDisposer autorun(
  1. dynamic fn(
    1. Reaction
  2. {String? name,
  3. int? delay,
  4. ReactiveContext? context,
  5. void onError(
    1. Object,
    2. Reaction

Executes the specified fn, whenever the dependent observables change. It returns a disposer that can be used to dispose the autorun.

Optional configuration:

  • name: debug name for this reaction
  • delay: throttling delay in milliseconds
var x = Observable(10);
var y = Observable(20);
var total = Observable(0);

var dispose = autorun((_){
  print('x = ${x}, y = ${y}, total = ${total}');

x.value = 20; // will cause autorun() to re-trigger.

dispose(); // This disposes the autorun() and will not be triggered again

x.value = 30; // Will not cause autorun() to re-trigger as it's disposed.


ReactionDisposer autorun(Function(Reaction) fn,
        {String? name,
        int? delay,
        ReactiveContext? context,
        void Function(Object, Reaction)? onError}) =>
    createAutorun(context ?? mainContext, fn,
        name: name, delay: delay, onError: onError);