com.vaadin.hilla.signals.

Class ListSignal<T>

java.lang.Object
com.vaadin.hilla.signals.Signal<T>
com.vaadin.hilla.signals.ListSignal<T>
public class ListSignal<T> extends Signal<T>
  • Constructor Details

    • ListSignal

      public ListSignal(Class<T> valueType)
    • ListSignal

      protected ListSignal(ListSignal<T> delegate)
  • Method Details

    • getDelegate

      protected ListSignal<T> getDelegate()

      Overrides:

      getDelegate in class Signal<T>

    • subscribe

      public reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode> subscribe(String signalId)

      Description copied from class: Signal

      Subscribes to an internal child signal with a specific signal id.

      Overrides:

      subscribe in class Signal<T>

      Parameters:

      signalId - the internal signal id

      Returns:

      a Flux of JSON events

    • submit

      public void submit(com.fasterxml.jackson.databind.node.ObjectNode event)

      Description copied from class: Signal

      Submits an event to the signal and notifies subscribers about the change of the signal value.

      Overrides:

      submit in class Signal<T>

      Parameters:

      event - the event to submit

    • submitToChild

      protected void submitToChild(com.fasterxml.jackson.databind.node.ObjectNode event)
    • createSnapshotEvent

      protected com.fasterxml.jackson.databind.node.ObjectNode createSnapshotEvent()

      Description copied from class: Signal

      Creates a snapshot event reflecting the current state of the signal.

      Specified by:

      createSnapshotEvent in class Signal<T>

      Returns:

      the snapshot event

    • processEvent

      protected com.fasterxml.jackson.databind.node.ObjectNode processEvent(com.fasterxml.jackson.databind.node.ObjectNode event)

      Description copied from class: Signal

      Processes the event and updates the signal value if needed. Note that this method is not thread-safe and should be called from a synchronized context.

      Specified by:

      processEvent in class Signal<T>

      Parameters:

      event - the event to process

      Returns:

      true if the event was successfully processed and the signal value was updated, false otherwise.

    • handleInsert

      protected ListStateEvent<T> handleInsert(ListStateEvent<T> event)
    • handleRemoval

      protected ListStateEvent<T> handleRemoval(ListStateEvent<T> event)
    • getEntry

      protected ListStateEvent.ListEntry<T> getEntry(UUID entryId)
    • withOperationValidator

      public ListSignal<T> withOperationValidator(OperationValidator<T> validator)

      Returns a new signal that validates the operations with the provided validator. As the same validator is for all operations, the validator should be able to handle all operations that the signal supports.

      For example, the following code creates a signal that disallows adding values containing the word "bad":

      
       ListSignal<String> signal = new ListSignal<>(String.class);
       ListSignal<String> noBadWordSignal = signal.withOperationValidator(op -> {
          if (op instanceof ListInsertOperation<String> insertOp && insertOp.value().contains("bad")) {
              return ValidationResult.reject("Bad words are not allowed");
          }
          return ValidationResult.allow();
       });
       
      In the example above, the validator does not cover the set and replace operations that can affect the entry values after insertion. A similar type checking can be done for the set and replace operation if needed. However, the ValueOperation type allows unifying the validation logic for all the operations that are manipulating the value. The following example shows how to define a validator that covers all the operations that can affect the entry values:
      
       ListSignal<String> signal = new ListSignal<>(String.class);
       ListSignal<String> noBadWordSignal = signal.withOperationValidator(op -> {
          if (op instanceof ValueOperation<String> valueOp && valueOp.value().contains("bad")) {
              return ValidationResult.reject("Bad words are not allowed");
          }
          return ValidationResult.allow();
       });
       
      As ListInsertOperation, SetValueOperation, and ReplaceValueOperation implement the ValueOperation, the validator covers all of these operations.

      Parameters:

      validator - the operation validator, not null

      Returns:

      a new signal that validates the operations with the provided validator

      Throws:

      NullPointerException - if the validator is null

    • asReadonly

      public ListSignal<T> asReadonly()

      Description copied from class: Signal

      Returns a read-only instance of the signal that rejects any attempt to modify the signal value. The read-only signal, however, receives the same updates as the original signal does.

      Specified by:

      asReadonly in class Signal<T>

      Returns:

      the read-only signal