peek method
In the rare instance that you have an effect that should write to
another signal based on the previous value, but you don't want the
effect to be subscribed to that signal, you can read a signals's
previous value via signal.peek()
.
final counter = signal(0);
final effectCount = signal(0);
effect(() {
print(counter.value);
// Whenever this effect is triggered, increase `effectCount`.
// But we don't want this signal to react to `effectCount`
effectCount.value = effectCount.peek() + 1;
});
Note that you should only use signal.peek()
if you really need it.
Reading a signal's value via signal.value
is the preferred way in most scenarios.
Implementation
@override
T peek() => instance.peek();