com.vaadin.hilla.signals.
Class ListSignal<T>
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
ListSignal
(ListSignal<T> delegate) ListSignal
(Class<T> valueType) -
Method Summary
Modifier and TypeMethodDescriptionReturns a read-only instance of the signal that rejects any attempt to modify the signal value.
protected com.fasterxml.jackson.databind.node.ObjectNode
Creates a snapshot event reflecting the current state of the signal.
protected ListSignal<T>
protected ListStateEvent.ListEntry<T>
protected ListStateEvent<T>
handleInsert
(ListStateEvent<T> event) protected ListStateEvent<T>
handleRemoval
(ListStateEvent<T> event) protected com.fasterxml.jackson.databind.node.ObjectNode
processEvent
(com.fasterxml.jackson.databind.node.ObjectNode event) Processes the event and updates the signal value if needed.
void
submit
(com.fasterxml.jackson.databind.node.ObjectNode event) Submits an event to the signal and notifies subscribers about the change of the signal value.
protected void
submitToChild
(com.fasterxml.jackson.databind.node.ObjectNode event) reactor.core.publisher.Flux<com.fasterxml.jackson.databind.node.ObjectNode>
Subscribes to an internal child signal with a specific signal id.
withOperationValidator
(OperationValidator<T> validator) Returns a new signal that validates the operations with the provided validator.
-
Constructor Details
-
ListSignal
-
ListSignal
-
-
Method Details
-
getDelegate
Overrides:
getDelegate
in classSignal<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.
-
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.
-
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 classSignal<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 classSignal<T>
Parameters:
event
- the event to processReturns:
true
if the event was successfully processed and the signal value was updated,false
otherwise. -
handleInsert
-
handleRemoval
-
getEntry
-
withOperationValidator
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":
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, theListSignal<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(); });
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:
AsListSignal<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(); });
ListInsertOperation
,SetValueOperation
, andReplaceValueOperation
implement theValueOperation
, the validator covers all of these operations.Parameters:
validator
- the operation validator, notnull
Returns:
a new signal that validates the operations with the provided validator
Throws:
NullPointerException
- if the validator isnull
-
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 classSignal<T>
Returns:
the read-only signal
-