run method
void
run()
Runs fn when this node is dirty or has pending dependencies.
Registered cleanups run before the body reruns. Dependency collection uses the active subscriber stack, and disposed effects are ignored.
Example:
final effect = EffectNode(() => print('tick'), lazy: true);
effect.run();
Implementation
void run() {
final flags = this.flags;
if (flags & (ReactiveFlags.dirty) != 0 ||
(flags & (ReactiveFlags.pending) != 0 && checkDirty(deps!, this))) {
if (flags & ReactiveFlags.hasChildEffect != 0) {
var link = depsTail;
while (link != null) {
final prev = link.prevDep;
final dep = link.dep;
if (dep is BaseEffectNode) {
unlink(link, this);
}
link = prev;
}
}
cleanup();
if (this.flags == ReactiveFlags.none) {
return;
}
this
..depsTail = null
..flags = ReactiveFlags.watching | ReactiveFlags.recursedCheck;
final prevSub = setActiveSub(this);
try {
++cycle;
++runDepth;
fn();
} finally {
--runDepth;
assert(() {
JoltDevTools.effect(this);
return true;
}());
activeSub = prevSub;
this.flags &= ~ReactiveFlags.recursedCheck;
purgeDeps(this);
}
} else if (deps != null) {
this.flags =
ReactiveFlags.watching | (flags & ReactiveFlags.hasChildEffect);
}
}