trigger<T> function
T
trigger<T>(
- T fn()
Runs fn while collecting the nodes it reads, then propagates those nodes.
This is useful for in-place mutations that keep object identity the same.
Reads inside fn decide which dependencies should notify subscribers after
the callback finishes.
Implementation
@pragma("vm:prefer-inline")
@pragma("wasm:prefer-inline")
@pragma("dart2js:prefer-inline")
T trigger<T>(T Function() fn) {
final sub = EffectNode(() {}, detach: true);
final prevSub = setActiveSub(sub);
try {
return fn();
} finally {
activeSub = prevSub;
sub.flags = ReactiveFlags.none;
var link = sub.deps;
while (link != null) {
final dep = link.dep;
link = unlink(link, sub);
final subs = dep.subs;
if (subs != null) {
propagate(subs, runDepth > 0);
shallowPropagate(subs);
}
}
if (batchDepth == 0) {
flushEffects();
}
}
}