MutableComputeCell<T> constructor
Create a MutableComputeCell with a given compute and reverse compute function.
The compute
function is called with no arguments whenever
the value of at least one cell in arguments
changes. It should return
the cell's value.
The reverseCompute
function is called when the value
of the cell is
set, with the new value passed as an argument to the function. It should
set the values of the argument cells accordingly such that calling compute
again will produce the same value that was passed to reverseCompute
.
reverseCompute
is called in a batch update, by MutableCell.batch, so
that the values of the argument cells are set simultaneously.
arguments
is a list of argument cells on which the value of the cell
depends.
If changesOnly
is true, the returned cell only notifies its observers
if its value has actually changed.
If key
is non-null it is used to identify the cell. NOTE, if key
is non null dispose
has to be called, when the cell is no longer used.
Example:
final a = MutableCell(1);
final b = MutableComputeCell(
arguments: [a],
compute: () => a.value + 1,
reverseCompute: (b) {
a.value = b - 1;
}
);
Implementation
MutableComputeCell({
required T Function() compute,
required void Function(T) reverseCompute,
required Set<ValueCell> arguments,
super.changesOnly,
super.key
}) : _compute = compute, _reverseCompute = reverseCompute, super(arguments);