com.vaadin.flow.internal.
Class StateTree
All Implemented Interfaces:
The state tree that is synchronized with the client-side.
For internal use only. May be renamed or removed in a future release.
Since:
1.0
Author:
Vaadin Ltd
See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
A task to be executed before the client response, together with an execution sequence number and context object.
static interface
A registration object for removing a task registered for execution before the client response.
-
Constructor Summary
ConstructorsConstructorDescriptionStateTree
(UIInternals uiInternals, Class<? extends NodeFeature>... features) Creates a new state tree with a set of features defined for the root node.
-
Method Summary
Modifier and TypeMethodDescriptionbeforeClientResponse
(StateNode context, SerializableConsumer<ExecutionContext> execution) Registers a task to be executed before the response is sent to the client.
void
collectChanges
(Consumer<NodeChange> collector) Collects all changes made to this tree since the last time
collectChanges(Consumer)
has been called.Gets all the nodes that have been marked.
getNodeById
(int id) Finds a node with the given id.
Gets the root node of this state tree.
getUI()
Gets the
UI
that this tree belongs to.boolean
Checks if there are nodes that have been marked as dirty since the last time
collectDirtyNodes()
was invoked.boolean
Check if given node is registered to this node owner.
boolean
isDirty()
Checks if there are changes waiting to be sent to the client side.
void
markAsDirty
(StateNode node) Marks a node owned by this instance as dirty.
void
Prepares the tree for resynchronization, meaning that the client will receive the same changes as when the component tree was initially attached, so that it can build the DOM tree from scratch.
int
Registers a node with this node owner.
void
Called internally by the framework before the response is sent to the client.
void
unregister
(StateNode node) Unregisters a node from this owner.
-
Constructor Details
-
StateTree
Creates a new state tree with a set of features defined for the root node.
Parameters:
features
- the features of the root nodeuiInternals
- the internals for the UI that this tree belongs to
-
-
Method Details
-
getRootNode
Gets the root node of this state tree. The root node is created together with the tree and can't be detached.
Returns:
the root node
-
register
Description copied from interface:
NodeOwner
Registers a node with this node owner. The new node should already be set to be owned by this instance.
-
unregister
Description copied from interface:
NodeOwner
Unregisters a node from this owner. This must be done before the node is set to not be owned by this instance.
Specified by:
unregister
in interfaceNodeOwner
Parameters:
node
- the node to unregister -
hasNode
Description copied from interface:
NodeOwner
Check if given node is registered to this node owner.
-
getNodeById
Finds a node with the given id.
Parameters:
id
- the node id to look forReturns:
the node with the given id;
null
if the id is not registered with this treeSee Also:
-
collectChanges
Collects all changes made to this tree since the last time
collectChanges(Consumer)
has been called.WARNING: This is an internal method which is not intended to be used outside. The only proper caller of this method is
UidlWriter
class (theUidlWriter::encodeChanges
method). Any call of this method in any other place will break the expectedUI
state.Parameters:
collector
- a consumer accepting node changes -
markAsDirty
Description copied from interface:
NodeOwner
Marks a node owned by this instance as dirty. Dirty nodes are collected from an owner using
collectDirtyNodes()
.Specified by:
markAsDirty
in interfaceNodeOwner
Parameters:
node
- the node to be marked as dirty -
collectDirtyNodes
Gets all the nodes that have been marked.
Returns:
a set of dirty nodes, in the order they were marked dirty
-
hasDirtyNodes
public boolean hasDirtyNodes()Checks if there are nodes that have been marked as dirty since the last time
collectDirtyNodes()
was invoked.Returns:
true if there are dirty nodes, false otherwise
-
getUI
Gets the
UI
that this tree belongs to.Returns:
the UI that this tree belongs to
-
beforeClientResponse
public StateTree.ExecutionRegistration beforeClientResponse(StateNode context, SerializableConsumer<ExecutionContext> execution) Registers a task to be executed before the response is sent to the client. The tasks are executed in order of registration. If tasks register more tasks, they are executed after all already registered tasks for the moment.
Example: three tasks are submitted,
A
,B
andC
, whereB
produces two more tasks during execution,D
andE
. The resulting execution would beABCDE
.If the
StateNode
related to the task is not attached to the document by the time the task is evaluated, the execution is postponed to before the next response.The task receives a
ExecutionContext
as parameter, which contains information about the node state before the response.Parameters:
context
- the StateNode relevant for the execution. Can not benull
execution
- the task to be executed. Can not benull
Returns:
a registration that can be used to cancel the execution of the task
-
runExecutionsBeforeClientResponse
public void runExecutionsBeforeClientResponse()Called internally by the framework before the response is sent to the client. All tasks registered at
beforeClientResponse(StateNode, SerializableConsumer)
are evaluated and executed if able. -
isDirty
public boolean isDirty()Checks if there are changes waiting to be sent to the client side.
Returns:
true
if there are pending changes,false
otherwise -
prepareForResync
public void prepareForResync()Prepares the tree for resynchronization, meaning that the client will receive the same changes as when the component tree was initially attached, so that it can build the DOM tree from scratch.
-