Search in sources :

Example 1 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class TemplateInitializer method doRequestAttachCustomElement.

private void doRequestAttachCustomElement(String id, String tag, JsonArray path) {
    if (registeredElementIdToInjected.containsKey(id)) {
        return;
    }
    // make sure that shadow root is available
    getShadowRoot();
    Element element = new Element(tag);
    VirtualChildrenList list = getElement().getNode().getFeature(VirtualChildrenList.class);
    list.append(element.getNode(), NodeProperties.TEMPLATE_IN_TEMPLATE, path);
    // anything else
    CustomElementRegistry.getInstance().wrapElementIfNeeded(element);
}
Also used : Element(com.vaadin.flow.dom.Element) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 2 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList 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 3 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplate_hasTextNodesInTemplate_correctRequestIndicesPath.

private void doParseTemplate_hasTextNodesInTemplate_correctRequestIndicesPath(TextNodesInHtmlTemplate template) {
    VirtualChildrenList feature = template.getStateNode().getFeature(VirtualChildrenList.class);
    JsonObject object = (JsonObject) feature.get(0).getFeature(ElementData.class).getPayload();
    JsonArray path = object.getArray(NodeProperties.PAYLOAD);
    // check arrays of indices
    assertEquals(1, path.length());
    assertEquals(1, (int) path.get(0).asNumber());
}
Also used : JsonArray(elemental.json.JsonArray) JsonObject(elemental.json.JsonObject) VirtualChildrenList(com.vaadin.flow.internal.nodefeature.VirtualChildrenList)

Example 4 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList 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)

Example 5 with VirtualChildrenList

use of com.vaadin.flow.internal.nodefeature.VirtualChildrenList in project flow by vaadin.

the class PolymerTemplateTest method doParseTemplte_hasChildTemplateOutsideDomRepeat_elementIsCreated.

private void doParseTemplte_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)

Aggregations

VirtualChildrenList (com.vaadin.flow.internal.nodefeature.VirtualChildrenList)11 StateNode (com.vaadin.flow.internal.StateNode)5 ArrayList (java.util.ArrayList)5 ElementData (com.vaadin.flow.internal.nodefeature.ElementData)3 Component (com.vaadin.flow.component.Component)2 Element (com.vaadin.flow.dom.Element)2 Test (org.junit.Test)2 UI (com.vaadin.flow.component.UI)1 JsonArray (elemental.json.JsonArray)1 JsonObject (elemental.json.JsonObject)1