Search in sources :

Example 6 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtTemplateBinderTest method testBindOverrideNode_attributes_afterBind.

public void testBindOverrideNode_attributes_afterBind() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    int id = 45;
    StateNode overrideNode = createSimpleOverrideNode(id);
    Element element = createElement(templateNode, id);
    NodeMap props = overrideNode.getMap(NodeFeatures.ELEMENT_ATTRIBUTES);
    props.getProperty("foo").setValue("bar");
    Reactive.flush();
    assertEquals("bar", element.getAttribute("foo"));
}
Also used : Element(elemental.dom.Element) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 7 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtTemplateBinderTest method testUnregister_textBinsingUpdateIsNotDone.

public void testUnregister_textBinsingUpdateIsNotDone() {
    TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY));
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue("foo");
    Node domNode = createText(templateNode);
    assertEquals("", domNode.getTextContent());
    stateNode.unregister();
    Reactive.flush();
    assertEquals("", domNode.getTextContent());
}
Also used : StateNode(com.vaadin.client.flow.StateNode) ChildSlotNode(com.vaadin.flow.template.angular.ChildSlotNode) Node(elemental.dom.Node) ForTemplateNode(com.vaadin.flow.template.angular.ForTemplateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 8 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtTemplateBinderTest method createNgForModelNode.

/**
 * Creates 3 children for the {@code parent}: the first one is defined via
 * the {@code firstChildTag}, the second is defined via the {@code ngForTag}
 * (this is the template which represents *ngFor) and the
 * {@code lastChildTag} defines the third child.
 * <p>
 * {@code collectionVar} is an outer scope collection variable name and
 * {@code textVar} is text template parameter name. It's used inside *ngFor
 * template.
 * <p>
 * So the result is:
 *
 * <pre>
 *                                 parent
 *                                   |
 *              ________________________________________________________
 *              |                          |                           |
 *      <firstChildTag>    <ngForTag>{{textVar}}</ngForTag>     <lastChildTag>
 * </pre>
 */
private StateNode createNgForModelNode(TestElementTemplateNode parent, String firstChildTag, String ngForTag, String lastChildTag, String collectionVar, String textVar) {
    TestElementTemplateNode child1 = TestElementTemplateNode.create(firstChildTag);
    int child1Id = 57;
    registry.getTemplateRegistry().register(child1Id, child1);
    TestForTemplateNode templateNode = TestTemplateNode.create(ForTemplateNode.TYPE);
    int templateId = 42;
    registry.getTemplateRegistry().register(templateId, templateNode);
    TestElementTemplateNode forChild = TestElementTemplateNode.create(ngForTag);
    templateNode.setCollectionVariable(collectionVar);
    TestTextTemplate text = TestTextTemplate.create(TestBinding.createTextValueBinding(textVar));
    int textChildId = 85;
    registry.getTemplateRegistry().register(textChildId, text);
    forChild.setChildrenIds(new double[] { textChildId });
    int forChildId = 11;
    registry.getTemplateRegistry().register(forChildId, forChild);
    templateNode.setChildrenIds(new double[] { forChildId });
    TestElementTemplateNode child2 = TestElementTemplateNode.create(lastChildTag);
    int child2Id = 84;
    registry.getTemplateRegistry().register(child2Id, child2);
    parent.setChildrenIds(new double[] { child1Id, templateId, child2Id });
    NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    MapProperty property = model.getProperty(collectionVar);
    StateNode modelNode = new StateNode(1, tree);
    property.setValue(modelNode);
    return modelNode;
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 9 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtTemplateBinderTest method testAttributeBindingNoValueTemplate.

public void testAttributeBindingNoValueTemplate() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    templateNode.addAttribute("attr", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
    Element domNode = createElement(templateNode);
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue(null);
    Reactive.flush();
    assertEquals(null, domNode.getAttribute("attr"));
}
Also used : Element(elemental.dom.Element) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 10 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtTemplateBinderTest method testNgFor_updateModel.

public void testNgFor_updateModel() {
    TestElementTemplateNode parent = TestElementTemplateNode.create("div");
    String textVar = "text";
    String collectionVar = "items";
    // create 3 children for the parent: <div/><li
    // *ngFor>{{text}}</li><span/>
    StateNode modelNode = createNgForModelNode(parent, "div", "li", "span", collectionVar, textVar);
    StateNode varNode = new StateNode(2, tree);
    varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("foo");
    modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
    Element element = createElement(parent);
    Reactive.flush();
    NodeMap model = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    MapProperty property = model.getProperty(collectionVar);
    modelNode = new StateNode(3, tree);
    property.setValue(modelNode);
    varNode = new StateNode(4, tree);
    varNode.getMap(NodeFeatures.TEMPLATE_MODELMAP).getProperty(textVar).setValue("bar");
    modelNode.getList(NodeFeatures.TEMPLATE_MODELLIST).add(0, varNode);
    Reactive.flush();
    assertEquals("DIV", element.getTagName());
    NodeList childNodes = element.getChildNodes();
    assertTrue(childNodes.getLength() > 1);
    assertEquals("DIV", ((Element) childNodes.item(0)).getTagName());
    assertEquals("SPAN", ((Element) childNodes.item(childNodes.getLength() - 1)).getTagName());
    Element li = ((Element) childNodes.item(childNodes.getLength() - 2));
    assertEquals("LI", li.getTagName());
    assertEquals(4, childNodes.getLength());
    // comment
    assertEquals(Node.COMMENT_NODE, childNodes.item(1).getNodeType());
    assertEquals("bar", li.getTextContent());
}
Also used : Element(elemental.dom.Element) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeList(elemental.dom.NodeList) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)68 StateNode (com.vaadin.client.flow.StateNode)30 Element (elemental.dom.Element)21 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)20 Node (elemental.dom.Node)14 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)10 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)10 JsonObject (elemental.json.JsonObject)8 Test (org.junit.Test)6 DomElement (com.vaadin.client.flow.dom.DomElement)5 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)4 NodeList (com.vaadin.client.flow.nodefeature.NodeList)4 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 Computation (com.vaadin.client.flow.reactive.Computation)3 NativeFunction (com.vaadin.client.flow.util.NativeFunction)3 JsonValue (elemental.json.JsonValue)3 Command (com.vaadin.client.Command)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsArray (com.vaadin.client.flow.collection.JsArray)2