watchComputed<R> method

Widget watchComputed<R>(
  1. R compute(),
  2. Widget builder(
    1. R value
    )
)

Watch a computed value derived from this model

Implementation

Widget watchComputed<R>(
  R Function() compute,
  Widget Function(R value) builder,
) {
  R cachedValue = compute();
  return ReactiveBuilder<T>(
    model: this,
    builder: (_) {
      final newValue = compute();
      if (cachedValue != newValue) cachedValue = newValue;
      return builder(cachedValue);
    },
  );
}