SelfCell<T> constructor

SelfCell<T>(
  1. SelfCompute<T> compute, {
  2. T? initialValue,
  3. dynamic key,
})

Create a computed cell which can access its own value.

The compute function is called to compute the value of the cell, with a self argument. The self argument returns the last computed value of the cell. self() returns initialValue when it is called while computing the first value of the cell. If initialValue is null and T is not nullable, an UninitializedCellError is thrown when calling self() while computing the first value of the cell.

The cell is identified by key if it is not null.

Implementation

factory SelfCell(SelfCompute<T> compute, {
  T? initialValue,
  key
}) {
  late final SelfCell<T> self;

  self = SelfCell._internal(() => compute(self._selfValue),
      key: key,
      initialValue: initialValue
  );

  return self;
}