Class ListSignal<T extends @Nullable Object>
- Type Parameters:
T- the element type
- All Implemented Interfaces:
Signal<@NonNull List<ValueSignal<T>>>,Serializable
Local signals are non-serializable and intended for UI-local state only. They do not participate in clustering and are simpler than shared signals.
Structural mutations (add, remove, clear) trigger list-level dependents. Entry-level mutations (updating an entry's value) only trigger that entry's dependents.
Local list signals can't be used inside signal transactions.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidHook for subclasses to perform precondition checks before accessing the value.voidclear()Removes all entries from this list.List<ValueSignal<T>> get()Gets the current value of this signal.Inserts a value at the given index in this list.insertFirst(T value) Inserts a value as the first entry in this list.insertLast(T value) Inserts a value as the last entry in this list.List<ValueSignal<T>> peek()Reads the value without setting up any dependencies.voidremove(ValueSignal<T> entry) Removes the given entry from this list.toString()Methods inherited from class com.vaadin.flow.signals.local.AbstractLocalSignal
assertLockHeld, getSignalValue, getSignalValueUnsafe, lock, setSignalValue, tryLock, unlock
-
Constructor Details
-
ListSignal
public ListSignal()Creates a new empty list signal.
-
-
Method Details
-
get
Description copied from interface:SignalGets 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.unboundEffect(EffectAction)orSignal.computed(SignalComputation)callback sets up that effect or computed signal to depend on the signal.This method must only be called within a reactive context such as an effect, a computed signal, an explicit
Signal.untracked(ValueSupplier)block, or atransaction. Calling it outside such a context throws anIllegalStateException. UseSignal.peek()for one-time reads that do not need dependency tracking.- Specified by:
getin interfaceSignal<T extends @Nullable Object>- Overrides:
getin classAbstractLocalSignal<@NonNull List<ValueSignal<T extends @Nullable Object>>>- Returns:
- the signal value
-
peek
Description copied from interface:SignalReads the value without setting up any dependencies. This method returns the same value asSignal.get()but without creating a dependency when used inside a transaction, effect or computed signal.Unlike
Signal.get(), this method can be called outside a reactive context and is the recommended way to read a signal value for one-time use, such as logging, assertions, or initializing non-reactive UI.- Specified by:
peekin interfaceSignal<T extends @Nullable Object>- Overrides:
peekin classAbstractLocalSignal<@NonNull List<ValueSignal<T extends @Nullable Object>>>- Returns:
- the signal value
-
checkPreconditions
protected void checkPreconditions()Description copied from class:AbstractLocalSignalHook for subclasses to perform precondition checks before accessing the value. Called while holding the lock. The base implementation verifies that the signal is not accessed from a different session than the one that first used it.- Overrides:
checkPreconditionsin classAbstractLocalSignal<@NonNull List<ValueSignal<T extends @Nullable Object>>>
-
insertFirst
Inserts a value as the first entry in this list.- Parameters:
value- the value to insert- Returns:
- a signal for the inserted entry
-
insertLast
Inserts a value as the last entry in this list.- Parameters:
value- the value to insert- Returns:
- a signal for the inserted entry
-
insertAt
Inserts a value at the given index in this list.Note: This method should only be used in non-concurrent cases where the list structure is not being modified by other threads. The index is sensitive to concurrent modifications and may lead to unexpected results if the list is modified between determining the index and calling this method. For concurrent cases, prefer using
insertFirst(Object)orinsertLast(Object).- Parameters:
index- the index at which to insert (0 for first, size() for last)value- the value to insert- Returns:
- a signal for the inserted entry
- Throws:
IndexOutOfBoundsException- if index is negative or greater than size()
-
remove
Removes the given entry from this list. Does nothing if the entry is not in the list.- Parameters:
entry- the entry to remove
-
clear
public void clear()Removes all entries from this list. -
toString
-