select<R> method

LxComputed<R> select<R>(
  1. R selector(
    1. T value
    )
)

Creates a specific selection of the state that only updates when the selected value changes.

This is useful for optimizing rebuilds when using large state objects. The selector receives the current value of the state.

// Example usage:

final state = {'count': 0, 'data': 'foo'}.lx;
final count = state.select((val) => val['count']);

Implementation

LxComputed<R> select<R>(R Function(T value) selector) {
  return LxComputed<R>(
    () => selector(value),
    staticDeps: true,
    eager: true,
    name: name != null ? '$name.select' : null,
  );
}