MutableCell<T>.computed constructor

MutableCell<T>.computed(
  1. T compute(),
  2. void reverse(
    1. T value
    ), {
  3. bool changesOnly = false,
  4. dynamic key,
})

Create a computational cell which can also have its value set directly.

The compute function is called to compute the value of the cell as a function of one or more argument cells. Any cell referenced in compute by the call method is considered an argument cell. Any change in the value of an argument cell will result in the value of the returned cell being recomputed.

NOTE: All argument cells referenced in compute must be MutableCell's.

Additionally this cell can also have its value changed by setting the value property directly. When the value property is set, reverse is called, with the newly assigned value. reverse should set the values of the argument cells such that calling compute again will produce the same value that was assigned to the value property.

reverse is called in a batch update, by batch, so that the values of the argument cells are set simultaneously.

If changesOnly is true, the returned cell only notifies its observers if its value has actually changed.

Example:

final a = MutableCell(1);
final b = MutableCell.computed(() => a() + 1, (b) => {
  a.value = b - 1;
});

Implementation

factory MutableCell.computed(T Function() compute, void Function(T value) reverse, {
  bool changesOnly = false,
  key
}) => DynamicMutableComputeCell(
    compute: compute,
    reverseCompute: reverse,
    changesOnly: changesOnly,
    key: key
);