autorun function
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 reactiondelay
: 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.
Implementation
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);