reaction<T> function Null safety

ReactionDisposer reaction<T>(
  1. T fn(
    1. Reaction
  2. void effect(
    1. T
  3. {String? name,
  4. int? delay,
  5. bool? fireImmediately,
  6. EqualityComparer<T>? equals,
  7. ReactiveContext? context,
  8. void onError(
    1. Object,
    2. Reaction

Executes the fn function and tracks the observables used in it. Returns a function to dispose the reaction.

The fn is supposed to return a value of type T. When it changes, the effect function is executed.

Note: Only the fn function is tracked and not the effect.

You can also pass in an optional name, a throttling delay in milliseconds. Use fireImmediately if you want to invoke the effect immediately without waiting for the fn to change its value. It is possible to define a custom equals function to override the default comparison for the value returned by fn, to have fined grained control over when the reactions should run.


ReactionDisposer reaction<T>(T Function(Reaction) fn, void Function(T) effect,
        {String? name,
        int? delay,
        bool? fireImmediately,
        EqualityComparer<T>? equals,
        ReactiveContext? context,
        void Function(Object, Reaction)? onError}) =>
    createReaction<T>(context ?? mainContext, fn, effect,
        name: name,
        delay: delay,
        equals: equals,
        fireImmediately: fireImmediately,
        onError: onError);