public class StateTree extends Object implements NodeOwner
Modifier and Type | Class and Description |
---|---|
static class |
StateTree.BeforeClientResponseEntry
A task to be executed before the client response, together with an
execution sequence number and context object.
|
static interface |
StateTree.ExecutionRegistration
A registration object for removing a task registered for execution before
the client response.
|
Constructor and Description |
---|
StateTree(UIInternals uiInternals,
Class<? extends NodeFeature>... features)
Creates a new state tree with a set of features defined for the root
node.
|
Modifier and Type | Method and Description |
---|---|
StateTree.ExecutionRegistration |
beforeClientResponse(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. |
Set<StateNode> |
collectDirtyNodes()
Gets all the nodes that have been marked.
|
StateNode |
getNodeById(int id)
Finds a node with the given id.
|
StateNode |
getRootNode()
Gets the root node of this state tree.
|
UI |
getUI()
Gets the
UI that this tree belongs to. |
boolean |
hasDirtyNodes()
Checks if there are nodes that have been marked as dirty since the last
time
collectDirtyNodes() was invoked. |
boolean |
hasNode(StateNode node)
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 |
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.
|
int |
register(StateNode node)
Registers a node with this node owner.
|
void |
runExecutionsBeforeClientResponse()
Called internally by the framework before the response is sent to the
client.
|
void |
unregister(StateNode node)
Unregisters a node from this owner.
|
@SafeVarargs public StateTree(UIInternals uiInternals, Class<? extends NodeFeature>... features)
features
- the features of the root nodeuiInternals
- the internals for the UI that this tree belongs topublic StateNode getRootNode()
public int register(StateNode node)
NodeOwner
public void unregister(StateNode node)
NodeOwner
unregister
in interface NodeOwner
node
- the node to unregisterpublic boolean hasNode(StateNode node)
NodeOwner
public StateNode getNodeById(int id)
id
- the node id to look fornull
if the id is not
registered with this treeStateNode.getId()
public void collectChanges(Consumer<NodeChange> collector)
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 (the UidlWriter::encodeChanges
method). Any call of this
method in any other place will break the expected UI
state.
collector
- a consumer accepting node changespublic void markAsDirty(StateNode node)
NodeOwner
collectDirtyNodes()
.markAsDirty
in interface NodeOwner
node
- the node to be marked as dirtypublic Set<StateNode> collectDirtyNodes()
public boolean hasDirtyNodes()
collectDirtyNodes()
was invoked.public UI getUI()
UI
that this tree belongs to.public StateTree.ExecutionRegistration beforeClientResponse(StateNode context, SerializableConsumer<ExecutionContext> execution)
Example: three tasks are submitted, A
, B
and C
,
where B
produces two more tasks during execution, D
and
E
. The resulting execution would be ABCDE
.
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.
context
- the StateNode relevant for the execution. Can not be
null
execution
- the task to be executed. Can not be null
public void runExecutionsBeforeClientResponse()
beforeClientResponse(StateNode, SerializableConsumer)
are
evaluated and executed if able.public boolean isDirty()
true
if there are pending changes,
false
otherwisepublic void prepareForResync()
Copyright © 2020. All rights reserved.