Search in sources :

Example 61 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class InertData method updateInertAndCascadeToChildren.

private void updateInertAndCascadeToChildren(Boolean resolvedParentInert) {
    boolean newInert = resolveInert(resolvedParentInert);
    if (cachedInert != null && cachedInert == newInert) {
        return;
    }
    // cascade update to all children unless those are ignoring parent
    // value or have same value and thus don't need updating.
    // (all explicitly updated nodes are visited separately)
    Deque<StateNode> stack = new ArrayDeque<>();
    getNode().forEachChild(stack::add);
    while (!stack.isEmpty()) {
        StateNode node = stack.pop();
        if (node.hasFeature(InertData.class)) {
            final Optional<InertData> featureIfInitialized = node.getFeatureIfInitialized(InertData.class);
            if (featureIfInitialized.isPresent()) {
                featureIfInitialized.get().updateInertAndCascadeToChildren(newInert);
            } else {
                node.forEachChild(stack::push);
            }
        } else {
            node.forEachChild(stack::push);
        }
    }
    cachedInert = newInert;
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayDeque(java.util.ArrayDeque)

Example 62 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplate_hasChildTemplateOutsideDomRepeat_elementIsCreated.

private void doParseTemplate_hasChildTemplateOutsideDomRepeat_elementIsCreated(TemplateWithDomRepeat template) {
    UI ui = new UI();
    ui.add(template);
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(1, templateNodes.size());
}
Also used : UI(com.vaadin.flow.component.UI) StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 63 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplateTest method attachExistingElement_injectedByIDdChild_onlyOneElementIsCreated.

@Test
public void attachExistingElement_injectedByIDdChild_onlyOneElementIsCreated() {
    TemplateInjectTemplate template = new TemplateInjectTemplate();
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(1, templateNodes.size());
    StateNode stateNode = templateNodes.get(0);
    assertEquals(stateNode, template.child.getStateNode());
    assertElementData(stateNode, NodeProperties.INJECT_BY_ID, "child");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList) Test(org.junit.Test)

Example 64 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplateTest method attachComponentAndVerifyChild.

private void attachComponentAndVerifyChild(PolymerTemplate<?> template, CustomComponent templateChild) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(1, templateNodes.size());
    StateNode child = templateNodes.get(0);
    String tag = child.getFeature(ElementData.class).getTag();
    assertEquals("div", tag);
    assertNotNull(templateChild);
    assertEquals(child, templateChild.getElement().getNode());
    assertTrue(templateChild.getElement().getComponent().isPresent());
    assertTrue(templateChild.getElement().getComponent().get() instanceof CustomComponent);
    assertEquals(templateChild, templateChild.getElement().getComponent().get());
    assertElementData(child, NodeProperties.INJECT_BY_ID, "child");
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) ElementData(com.vaadin.flow.internal.nodefeature.ElementData) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 65 with StateNode

use of com.vaadin.flow.internal.StateNode in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplate_hasChildTemplate_elementIsCreatedAndSetAsVirtualChild.

private void doParseTemplate_hasChildTemplate_elementIsCreatedAndSetAsVirtualChild(PolymerTemplate<?> template) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    List<StateNode> templateNodes = new ArrayList<>();
    feature.forEachChild(templateNodes::add);
    assertEquals(2, templateNodes.size());
    StateNode child1 = templateNodes.get(0);
    StateNode child2 = templateNodes.get(1);
    String tag = child1.getFeature(ElementData.class).getTag();
    if ("child-template".equals(tag)) {
        assertEquals("ffs", child2.getFeature(ElementData.class).getTag());
    } else {
        assertEquals("ffs", child1.getFeature(ElementData.class).getTag());
        assertEquals("child-template", child2.getFeature(ElementData.class).getTag());
    }
    assertTemplateInTempalte(child1);
    assertTemplateInTempalte(child2);
}
Also used : StateNode(com.vaadin.flow.internal.StateNode) ArrayList(java.util.ArrayList) ElementData(com.vaadin.flow.internal.nodefeature.ElementData) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Aggregations

StateNode (com.vaadin.flow.internal.StateNode)196 Test (org.junit.Test)122 Element (com.vaadin.flow.dom.Element)32 JsonObject (elemental.json.JsonObject)24 ElementPropertyMap (com.vaadin.flow.internal.nodefeature.ElementPropertyMap)22 UI (com.vaadin.flow.component.UI)19 StateTree (com.vaadin.flow.internal.StateTree)18 TemplateNode (com.vaadin.flow.template.angular.TemplateNode)18 ArrayList (java.util.ArrayList)18 StateNodeTest (com.vaadin.flow.internal.StateNodeTest)17 Serializable (java.io.Serializable)17 ModelMap (com.vaadin.flow.internal.nodefeature.ModelMap)16 ModelList (com.vaadin.flow.internal.nodefeature.ModelList)10 TemplateElementStateProviderTest (com.vaadin.flow.dom.TemplateElementStateProviderTest)9 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)9 VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)9 ElementTemplateNode (com.vaadin.flow.template.angular.ElementTemplateNode)9 Bean (com.vaadin.flow.templatemodel.Bean)9 HashMap (java.util.HashMap)9 Collectors (java.util.stream.Collectors)9