Class SignalBindingFeature
java.lang.Object
com.vaadin.flow.internal.nodefeature.NodeFeature
com.vaadin.flow.internal.nodefeature.ServerSideFeature
com.vaadin.flow.internal.nodefeature.SignalBindingFeature
- All Implemented Interfaces:
Serializable
Node feature for binding
Signals to various properties of a node.
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringCache slot for the signal returned byElement.sizeSignal(), not a rendered binding like the other keys: the value flows from the client to the signal through a resize trigger instead of from the signal to a client-side property, and nothing reads the binding exceptsizeSignal()itself, which uses it to return the same signal for every call.static final Stringstatic final Stringstatic final Stringstatic final String -
Constructor Summary
ConstructorsConstructorDescriptionCreates a SignalBindingFeature for the given node. -
Method Summary
Modifier and TypeMethodDescriptionGets the signal bound to the given key.<T> @Nullable SerializableConsumer<T> getWriteCallback(String key) Gets the write callback for the given key.booleanhasAnyBinding(String keyPrefix) Checks whether there is any binding with a key starting with the given prefix.booleanhasBinding(String key) Checks whether there is a binding for the given key.voidsetBinding(String key, Signal<?> signal) Sets a binding for the given key.voidsetBinding(String key, Signal<?> signal, @Nullable SerializableConsumer<?> writeCallback) Sets a binding for the given key with a write callback.<T extends @Nullable Object>
booleanupdateSignalByWriteCallback(String key, T oldValue, T newValue, SerializableBiPredicate<T, T> valueEquals, SerializableConsumer<T> revertCallback) Updates the signal value by invoking the write callback for the given key.Methods inherited from class com.vaadin.flow.internal.nodefeature.ServerSideFeature
collectChanges, forEachChild, generateChangesFromEmptyMethods inherited from class com.vaadin.flow.internal.nodefeature.NodeFeature
allowsChanges, attachPotentialChild, detatchPotentialChild, getNode, onAttach, onDetach
-
Field Details
-
TEXT
- See Also:
-
CLASSES
- See Also:
-
CLASS_GROUP
- See Also:
-
ENABLED
- See Also:
-
VALUE
- See Also:
-
THEMES
- See Also:
-
THEME_GROUP
- See Also:
-
HTML_CONTENT
- See Also:
-
CHILDREN
- See Also:
-
SIZE
Cache slot for the signal returned byElement.sizeSignal(), not a rendered binding like the other keys: the value flows from the client to the signal through a resize trigger instead of from the signal to a client-side property, and nothing reads the binding exceptsizeSignal()itself, which uses it to return the same signal for every call.- Since:
- 25.3
- See Also:
-
-
Constructor Details
-
SignalBindingFeature
Creates a SignalBindingFeature for the given node.- Parameters:
node- the node which supports the feature
-
-
Method Details
-
setBinding
Sets a binding for the given key.- Parameters:
key- the keysignal- the signal
-
setBinding
public void setBinding(String key, Signal<?> signal, @Nullable SerializableConsumer<?> writeCallback) Sets a binding for the given key with a write callback.- Parameters:
key- the keysignal- the signalwriteCallback- the callback to propagate value changes back, ornullfor a read-only binding
-
hasBinding
Checks whether there is a binding for the given key.- Parameters:
key- the key- Returns:
- true if there is a binding for the given key, false otherwise
-
hasAnyBinding
Checks whether there is any binding with a key starting with the given prefix.- Parameters:
keyPrefix- the key prefix- Returns:
- true if there is any binding with a key starting with the given prefix, false otherwise
-
getWriteCallback
Gets the write callback for the given key.- Type Parameters:
T- the type of the consumer value- Parameters:
key- the key- Returns:
- the write callback for the given key, or null if no callback is set
-
getSignal
Gets the signal bound to the given key.- Type Parameters:
T- the type of the signal value- Parameters:
key- the key- Returns:
- the signal bound to the given key, or null if no signal is bound
-
updateSignalByWriteCallback
public <T extends @Nullable Object> boolean updateSignalByWriteCallback(String key, T oldValue, T newValue, SerializableBiPredicate<T, T> valueEquals, SerializableConsumer<T> revertCallback) Updates the signal value by invoking the write callback for the given key. The callback is expected to update the signal value, and this method will check whether the signal value was updated to the expected new value. If the signal value differs from the expected new value after the callback, the revert callback will be invoked with the current signal value to revert the change.The new value may originate from the client, in which case there is no guarantee that its type matches the value type of the bound signal. The write callback rejects such a value either with a
ClassCastExceptionfrom the cast that the compiler generated into the callback or with anInvalidSignalValueTypeExceptionfrom the signal itself when generic code has erased that cast. Since the only purpose of the callback is to pass the value on to the signal, both cases are logged and reverted rather than propagated.- Type Parameters:
T- the type of the signal value- Parameters:
key- the key for which to update the signal valueoldValue- the old value before the update, used for comparison in case of revertnewValue- the expected new value to be set by the write callbackvalueEquals- a predicate to compare signal values for equalityrevertCallback- a callback to revert the component value to the updated signal's value if the signal value does not match the expected new value after invoking the write callback- Returns:
- true if the signal value was updated to the expected new value, false if a revert was performed
-