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);
}
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");
}
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());
}
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);
}
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());
}
Aggregations