EffectNode constructor
EffectNode(
- void fn(), {
- bool lazy = false,
- bool detach = false,
- JoltDebugOption? debug,
Creates an effect node that invokes fn in a reactive subscriber context.
Unless lazy is true, fn runs immediately. When detach is true,
this effect is not linked to the current parent scope or subscriber.
Implementation
EffectNode(this.fn,
{bool lazy = false, bool detach = false, JoltDebugOption? debug})
: super(flags: ReactiveFlags.watching | ReactiveFlags.recursedCheck) {
assert(() {
JoltDevTools.create(this, debug);
return true;
}());
final prevSub = setActiveSub(this);
if (prevSub != null && !detach) {
link(this, prevSub, 0);
prevSub.flags |= ReactiveFlags.hasChildEffect;
}
if (!lazy) {
try {
++runDepth;
fn();
} finally {
--runDepth;
assert(() {
JoltDevTools.effect(this);
return true;
}());
}
}
setActiveSub(prevSub);
flags &= ~ReactiveFlags.recursedCheck;
}