Class MappedModifySignal<P,C>

java.lang.Object
com.vaadin.flow.signals.impl.MappedModifySignal<P,C>
Type Parameters:
P - the parent signal value type
C - the child (this signal's) value type
All Implemented Interfaces:
Signal<C>, WritableSignal<C>, Serializable

public class MappedModifySignal<P,C> extends Object implements WritableSignal<C>
A writable signal that provides a two-way mapped view of a ValueSignal using in-place modification. Reading the signal applies a getter function to extract a child value from the parent. Writing to the signal uses a modifier function to update the parent value in place.

This is useful for mutable bean patterns where the parent object's properties are modified directly using setters.

See Also:
  • Constructor Details

    • MappedModifySignal

      public MappedModifySignal(ValueSignal<P> parent, SignalMapper<P,C> getter, SignalModifier<P,C> modifier)
      Creates a new mapped modify signal.
      Parameters:
      parent - the parent value signal to map, not null
      getter - the function to extract the child value from the parent, not null
      modifier - the function to modify the parent value in place with the new child value, not null
  • Method Details

    • get

      public C get()
      Description copied from interface: Signal
      Gets the current value of this signal. The value is read in a way that takes the current transaction into account and in the case of clustering also changes that have been submitted to the cluster but not yet confirmed.

      If the signal implementation supports transactions, then reading the value in a regular (i.e. Transaction.Type.STAGED) transaction makes the transaction depend on the value so that the transaction fails in case the signal value is changed concurrently.

      Reading the value inside an Signal.effect(EffectAction) or Signal.computed(SignalComputation) callback sets up that effect or computed signal to depend on the signal.

      Specified by:
      get in interface Signal<P>
      Returns:
      the signal value
    • peek

      public C peek()
      Description copied from interface: Signal
      Reads the value without setting up any dependencies. This method returns the same value as Signal.get() but without creating a dependency when used inside a transaction, effect or computed signal.
      Specified by:
      peek in interface Signal<P>
      Returns:
      the signal value
    • set

      public SignalOperation<C> set(C newChildValue)
      Description copied from interface: WritableSignal
      Sets the value of this signal. The result of the returned operation will be resolved with the previous value at the time when this operation was confirmed.
      Specified by:
      set in interface WritableSignal<P>
      Parameters:
      newChildValue - the value to set
      Returns:
      an operation containing the eventual result
    • replace

      public SignalOperation<Void> replace(C expectedValue, C newValue)
      Description copied from interface: WritableSignal
      Sets the value of this signal if and only if the signal has the expected value at the time when the operation is confirmed. This is the signal counterpart to AtomicReference.compareAndSet(Object, Object). The result of the returned operation will be resolved as successful if the expected value was present and resolved as unsuccessful if any other value was present when the operation is processed.
      Specified by:
      replace in interface WritableSignal<P>
      Parameters:
      expectedValue - the expected value
      newValue - the new value
      Returns:
      an operation containing the eventual result
    • update

      public CancelableOperation<C> update(SignalUpdater<C> childUpdater)
      Description copied from interface: WritableSignal
      Updates the signal value based on the given callback. The callback receives the current signal value and returns the new value to use. If the original value has changed by the time this change is confirmed, then the returned value is ignored and the callback is run again with the new value as input. This process is repeated until cancelled or until the update succeeds without conflicting changes.

      The process can be cancelled through the returned operation instance. Note that canceling will only prevent further retries but the change will still be made if the currently running attempt succeeds.

      The result of the returned operation will be resolved with the previous value at the time when a successful update operation was confirmed.

      Update operations cannot participate in transactions since any retry would occur after the original transaction has already been committed. For this reason, the whole operation completely bypasses all transaction handling.

      Specified by:
      update in interface WritableSignal<P>
      Parameters:
      childUpdater - the value update callback, not null
      Returns:
      an operation containing the eventual result