com.vaadin.signals.impl.
Class ComputedSignal<T>
Type Parameters:
T
- the value type
A signal with a value that is computed based on the value of other signals.
The signal value will be lazily re-computed when needed after the value has
changed for any of the signals that were used when computing the previous
value. An effect
or computed signal that uses
the value from a computed signal will not be invalidated if the computation
is run again but produces the same value as before.
-
Field Summary
Fields inherited from class com.vaadin.signals.Signal
ANYTHING_GOES
-
Constructor Summary
ConstructorsConstructorDescriptionComputedSignal
(Supplier<T> computation) Creates a new computed signal with the provided compute callback.
-
Method Summary
Modifier and TypeMethodDescriptionasNode()
Converts this signal into a node signal.
protected UsageTracker.Usage
createUsage
(Transaction transaction) Creates a usage instance based on the current state of this signal.
protected T
extractValue
(Node.Data data) Extracts the value for this signal from the given signal data node.
peek()
Reads the value without setting up any dependencies.
Reads the confirmed value without setting up any dependencies.
protected Object
usageChangeValue
(Node.Data data) Gets a reference value that will be used to determine whether a dependency based on previous usage should be invalidated.
Methods inherited from class com.vaadin.signals.Signal
clear, computed, data, data, effect, fromJson, id, map, mergeValidators, nodeValue, remove, runInTransaction, runInTransaction, runWithoutTransaction, runWithoutTransaction, submit, submit, submit, submitInsert, submitVoidOperation, toJson, tree, untracked, validator, value
-
Constructor Details
-
ComputedSignal
Creates a new computed signal with the provided compute callback.
Parameters:
computation
- a callback that returns the computed value, not null
-
-
Method Details
-
createUsage
Creates a usage instance based on the current state of this signal.
The usage instance from the super implementation is wrapped to count how many active external listeners there are. The external listener might become inactive either by returning
false
or through explicit unregistering, so both those sources are wrapped to accurately keep track of when the listener is no longer active.Overrides:
createUsage
in classSignal<T>
Parameters:
transaction
- the transaction for which the usage occurs, notnull
Returns:
a usage instance, not
null
-
extractValue
Description copied from class:
Signal
Extracts the value for this signal from the given signal data node.
Specified by:
extractValue
in classSignal<T>
Parameters:
data
- the data node to extract the value from, ornull
if the node doesn't exist in the treeReturns:
the signal value
-
usageChangeValue
Description copied from class:
Signal
Gets a reference value that will be used to determine whether a dependency based on previous usage should be invalidated. This is done by getting one reference value when the dependency occurs and then comparing that to the current value to determine if the value has changed.
The implementation should return an object that changes if and only if the
Signal.value()
of this signal changes.Specified by:
usageChangeValue
in classSignal<T>
Parameters:
data
- the data node to read from, notnull
Returns:
a reference value to use for validity checks, may be
null
-
peekConfirmed
Description copied from class:
Signal
Reads the confirmed value without setting up any dependencies. The confirmed value doesn't consider changes in the current transaction or changes that have been submitted but not yet confirmed in a cluster.
Overrides:
peekConfirmed
in classSignal<T>
Returns:
the confirmed signal value
-
peek
Description copied from class:
Signal
Reads the value without setting up any dependencies. This method returns the same value as
Signal.value()
but without creating a dependency when used inside a transaction, effect or computed signal. -
asNode
Description copied from class:
Signal
Converts this signal into a node signal. This allows further conversion into any specific signal type through the methods in
NodeSignal
. The converted signal is backed by the same underlying data and uses the same validator as this signal.
-