reaction<T> function
ReactionDisposer
reaction<T>(
- T fn(),
- void effect(
- T
- String? name,
- int? delay,
- bool? fireImmediately,
- EqualityComparer<
T> ? equals, - ReactiveContext? context,
- void onError()?,
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.
Implementation
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);