mutableApply<U> method

MutableCell<U> mutableApply<U>(
  1. U fn(
    1. T1,
    2. T2,
    3. T3,
    4. T4,
    ),
  2. void reverse(
    1. U
    ), {
  3. dynamic key,
  4. bool changesOnly = false,
})

Create a MutableComputeCell with given compute and reverse compute functions, and the cells in this as the argument list.

The fn function is called with the values of the cells in this passed as arguments whenever the value of at least one cell in this changes. It should return the cell's value.

The reverse 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 fn again will produce the same value that was passed to reverse.

reverse is called in a batch update, by MutableCell.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.

If key is non-null a MutableCellView identified by key is returned. If key is null a MutableComputeCell is returned.

Implementation

MutableCell<U> mutableApply<U>(U Function(T1, T2, T3, T4) fn, void Function(U) reverse, {
  key,
  bool changesOnly = false
}) {
  if (key == null) {
    return MutableComputeCell(
      compute: () => fn($1.value, $2.value, $3.value, $4.value),
      reverseCompute: reverse,
      arguments: {$1, $2, $3, $4},
      changesOnly: changesOnly
    );
  }
  else if (changesOnly) {
    return apply(fn, key: key != null ? _MutableApplyKey(this, key) : null)
        .store(changesOnly: true)
        .mutableApply((p0) => p0, reverse, key: key);
  }

  return MutableCellView(
    key: key,
    compute: () => fn($1.value, $2.value, $3.value, $4.value),
    reverse: reverse,
    arguments: {$1, $2, $3, $4},
  );
}