Search in sources :

Example 1 with NodeMap

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

the class SimpleElementBindingStrategy method listenToSubPropertiesChanges.

private void listenToSubPropertiesChanges(Element htmlNode, String polymerModelPath, int subNodeIndex, Object item) {
    if (item instanceof StateNode) {
        StateNode stateNode = (StateNode) item;
        NodeMap feature = null;
        if (stateNode.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
            feature = stateNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
        } else if (stateNode.hasFeature(NodeFeatures.BASIC_TYPE_VALUE)) {
            feature = stateNode.getMap(NodeFeatures.BASIC_TYPE_VALUE);
        }
        if (feature != null) {
            feature.addPropertyAddListener(event -> {
                Command command = () -> PolymerUtils.setListValueByIndex(htmlNode, polymerModelPath, subNodeIndex, PolymerUtils.convertToJson(event.getProperty()));
                invokeWhenNodeIsConstructed(command, stateNode);
            });
        }
    }
}
Also used : Command(com.vaadin.client.Command) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 2 with NodeMap

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

the class GwtTemplateBinderTest method testAttributeBindingTemplate.

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

Example 3 with NodeMap

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

the class GwtTemplateBinderTest method testUpdateAttributeBindingTemplate.

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

Example 4 with NodeMap

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

the class GwtTemplateBinderTest method testJSExpressionInBinding.

public void testJSExpressionInBinding() {
    // create binding with expression : : key ? key+'@bar.com' :'foo'
    TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY + " ? " + MODEL_KEY + "+'@bar.com' : 'foo'"));
    Node domNode = createText(templateNode);
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue(null);
    Reactive.flush();
    assertEquals("foo", domNode.getTextContent());
    map.getProperty(MODEL_KEY).setValue("value");
    Reactive.flush();
    assertEquals("value@bar.com", 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 5 with NodeMap

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

the class GwtTemplateBinderTest method testPropertyBindingNoValueTemplate.

public void testPropertyBindingNoValueTemplate() {
    TestElementTemplateNode templateNode = TestElementTemplateNode.create("div");
    templateNode.addProperty("prop", TestBinding.createBinding(ModelValueBindingProvider.TYPE, MODEL_KEY));
    Node domNode = createElement(templateNode);
    NodeMap map = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    map.getProperty(MODEL_KEY).setValue(null);
    Reactive.flush();
    assertEquals(null, WidgetUtil.getJsProperty(domNode, "prop"));
}
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)

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