Class StateTree
- All Implemented Interfaces:
NodeOwner,Serializable
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 classA task to be executed before the client response, together with an execution sequence number and context object.static interfaceA 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.voidcollectChanges(Consumer<NodeChange> collector) Collects all changes made to this tree since the last timecollectChanges(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 theUIthat this tree belongs to.booleanChecks if there are nodes that have been marked as dirty since the last timecollectDirtyNodes()was invoked.booleanCheck if given node is registered to this node owner.booleanisDirty()Checks if there are changes waiting to be sent to the client side.booleanChecks whether the state tree is in the process of preparing for resynchronization.voidmarkAsDirty(StateNode node) Marks a node owned by this instance as dirty.voidPrepares 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.intRegisters a node with this node owner.voidCalled internally by the framework before the response is sent to the client.voidunregister(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:
uiInternals- the internals for the UI that this tree belongs tofeatures- the features of the root node
-
-
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:NodeOwnerRegisters a node with this node owner. The new node should already be set to be owned by this instance. -
unregister
Description copied from interface:NodeOwnerUnregisters a node from this owner. This must be done before the node is set to not be owned by this instance.- Specified by:
unregisterin interfaceNodeOwner- Parameters:
node- the node to unregister
-
hasNode
Description copied from interface:NodeOwnerCheck if given node is registered to this node owner. -
getNodeById
Finds a node with the given id.- Parameters:
id- the node id to look for- Returns:
- the node with the given id;
nullif the id is not registered with this tree - See Also:
-
collectChanges
Collects all changes made to this tree since the last timecollectChanges(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
UidlWriterclass (theUidlWriter::encodeChangesmethod). Any call of this method in any other place will break the expectedUIstate.- Parameters:
collector- a consumer accepting node changes
-
markAsDirty
Description copied from interface:NodeOwnerMarks a node owned by this instance as dirty. Dirty nodes are collected from an owner usingcollectDirtyNodes().- Specified by:
markAsDirtyin 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 timecollectDirtyNodes()was invoked.- Returns:
- true if there are dirty nodes, false otherwise
-
getUI
Gets theUIthat 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,BandC, whereBproduces two more tasks during execution,DandE. The resulting execution would beABCDE.If the
StateNoderelated 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
ExecutionContextas parameter, which contains information about the node state before the response.- Parameters:
context- the StateNode relevant for the execution. Can not benullexecution- 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 atbeforeClientResponse(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:
trueif there are pending changes,falseotherwise
-
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. -
isPreparingForResync
public boolean isPreparingForResync()Checks whether the state tree is in the process of preparing for resynchronization. Resynchronization involves sending the same changes to the client as when the component tree was initially attached, enabling the client to rebuild the DOM tree from scratch.- Returns:
trueif the tree is preparing for resynchronization,falseotherwise
-