Package com.vaadin.client.flow
Class StateTree
java.lang.Object
com.vaadin.client.flow.StateTree
A client-side representation of a server-side state tree.
- Since:
- 1.0
- Author:
- Vaadin Ltd
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetNode(int id) Finds the node with the given id.Gets theRegistrythat this state tree belongs to.Gets the root node of this tree.getStateNodeForDomNode(DomNode domNode) Returns the state node in the tree for the given dom node ornullif none found.booleanChecks whether thenodeis active.booleanisResync()Check if tree is resynchronizing after aprepareForResync()booleanReturns whether this tree is currently being updated byTreeChangeProcessor.processChanges(StateTree, JsonArray).booleanReturns the visibility state of thenode.voidUnregisters all nodes except root from this tree, and clears the root's features.final voidregisterNode(StateNode node) Registers a node with this tree.voidsendEventToServer(StateNode node, String eventType, elemental.json.JsonObject eventData) Sends an event to the server.voidsendExistingElementAttachToServer(StateNode parent, int requestedId, int assignedId, String tagName, int index) Sends a data for attach existing element server side callback.voidsendExistingElementWithIdAttachToServer(StateNode parent, int requestedId, int assignedId, String id) Sends a data for attach existing element with id server side callback.voidsendNodePropertySyncToServer(MapProperty property) Sends a map property sync to the server.voidsendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId) Sends a request to call server side method withmethodNameusingargsArrayas argument values.voidsetResync(boolean resync) Set the resynchronization state for the StateTree.voidsetUpdateInProgress(boolean updateInProgress) Mark this tree as being updated.voidunregisterNode(StateNode node) Unregisters a node from this tree.
-
Constructor Details
-
StateTree
Creates a new instance connected to the given registry.- Parameters:
registry- the global registry
-
-
Method Details
-
setUpdateInProgress
public void setUpdateInProgress(boolean updateInProgress) Mark this tree as being updated.- Parameters:
updateInProgress-trueif the tree is being updated,falseif not- See Also:
-
isUpdateInProgress
public boolean isUpdateInProgress()Returns whether this tree is currently being updated byTreeChangeProcessor.processChanges(StateTree, JsonArray).- Returns:
trueif being updated,falseif not
-
registerNode
Registers a node with this tree.- Parameters:
node- the node to register
-
unregisterNode
Unregisters a node from this tree. Once the node has been unregistered, it can't be registered again.- Parameters:
node- the node to unregister
-
prepareForResync
public void prepareForResync()Unregisters all nodes except root from this tree, and clears the root's features. Use to reset the tree in preparation for rebuilding it in in a resynchronization response. -
isResync
public boolean isResync()Check if tree is resynchronizing after aprepareForResync()- Returns:
- true if resync called
-
setResync
public void setResync(boolean resync) Set the resynchronization state for the StateTree.- Parameters:
resync- resynchronization state to set
-
getStateNodeForDomNode
Returns the state node in the tree for the given dom node ornullif none found.Comparison is done with Node.isSameNode() method which is same as
===comparison.- Parameters:
domNode- the dom node to find state node for- Returns:
- the state node or null
-
getNode
Finds the node with the given id.- Parameters:
id- the id- Returns:
- the node with the given id, or
nullif no such node is registered.
-
getRootNode
Gets the root node of this tree.- Returns:
- the root node
-
sendEventToServer
public void sendEventToServer(StateNode node, String eventType, elemental.json.JsonObject eventData) Sends an event to the server.- Parameters:
node- the node that listened to the eventeventType- the type of eventeventData- extra data associated with the event
-
sendNodePropertySyncToServer
Sends a map property sync to the server.- Parameters:
property- the property that should have its value synced to the server, notnull
-
sendTemplateEventToServer
public void sendTemplateEventToServer(StateNode node, String methodName, JsArray<?> argsArray, int promiseId) Sends a request to call server side method withmethodNameusingargsArrayas argument values.In cases when the state tree has been changed and we receive a delayed or deferred template event the event is just ignored.
- Parameters:
node- the node referring to the server side instance containing the methodmethodName- the method nameargsArray- the arguments array for the methodpromiseId- the promise id to use for getting the result back, or -1 if no result is expected
-
sendExistingElementAttachToServer
public void sendExistingElementAttachToServer(StateNode parent, int requestedId, int assignedId, String tagName, int index) Sends a data for attach existing element server side callback.- Parameters:
parent- parent of the node to attachrequestedId- originally requested id of a server side nodeassignedId- identifier which should be used on the server side for the element (instead of requestedId)tagName- the requested tagNameindex- the index of the element on the server side
-
sendExistingElementWithIdAttachToServer
public void sendExistingElementWithIdAttachToServer(StateNode parent, int requestedId, int assignedId, String id) Sends a data for attach existing element with id server side callback.- Parameters:
parent- parent of the node to attachrequestedId- originally requested id of a server side nodeassignedId- identifier which should be used on the server side for the element (instead of requestedId)id- id of requested element
-
getRegistry
Gets theRegistrythat this state tree belongs to.- Returns:
- the registry of this tree, not
null
-
isVisible
Returns the visibility state of thenode.- Parameters:
node- the node whose visibility is tested- Returns:
trueis the node is visible,falseotherwise
-
isActive
Checks whether thenodeis active.The node is active if it's visible and all its ancestors are visible.
- Parameters:
node- the node whose activity is tested- Returns:
trueis the node is active,falseotherwise
-