getPeek<T> static method

T? getPeek<T>()

Returns the pending value of the currently executing computed node.

This static method can only be called from within a computed getter function. It returns the pending value (the value being computed) of the current computed node. This is useful for advanced scenarios where you need to access the previous or current pending value during computation, such as when implementing custom equality checks or mutations.

Important: This method will throw a StateError if called outside of a computed getter context.

Example:

final signal = Signal(0);
final computed = Computed(() {
  signal.value;
  final previous = Computed.getPeek<List<int>?>();
  // Use previous value for comparison or mutation
  return List.generate(3, (index) => index);
}, equals: equalList);

Implementation

@pragma("vm:prefer-inline")
@pragma("wasm:prefer-inline")
@pragma("dart2js:prefer-inline")
static T? getPeek<T>() {
  if (activeSub is! ComputedReactiveNode) {
    throw (StateError('Cannot get peek from non-computed node'));
  }
  return (activeSub as ComputedReactiveNode).pendingValue as T?;
}