Search in sources :

Example 11 with NodeMap

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

the class GwtTemplateBinderTest method testUpdatePropertyBindingTemplate.

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

Example 12 with NodeMap

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

the class GwtTemplateBinderTest method testBindOverrideNode_properties_afterBind.

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

Example 13 with NodeMap

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

the class GwtTemplateBinderTest method testJSExpresisonsWithSubProperties.

public void testJSExpresisonsWithSubProperties() {
    JsonObject beanType = Json.createObject();
    beanType.put(MODEL_KEY, "String");
    JsonObject modelType = Json.createObject();
    modelType.put(MODEL_KEY, beanType);
    setModelType(stateNode, modelType);
    // create binding with expression : : key.key ? key.key+'@bar.com'
    // :'foo'
    TestTextTemplate templateNode = TestTextTemplate.create(TestBinding.createTextValueBinding(MODEL_KEY + "." + MODEL_KEY + " ? " + MODEL_KEY + "." + MODEL_KEY + "+'@bar.com' : 'foo'"));
    Node domNode = createText(templateNode);
    NodeMap parentMap = stateNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    StateNode childNode = new StateNode(458, stateNode.getTree());
    NodeMap childMap = childNode.getMap(NodeFeatures.TEMPLATE_MODELMAP);
    parentMap.getProperty(MODEL_KEY).setValue(childNode);
    childMap.getProperty(MODEL_KEY).setValue(null);
    Reactive.flush();
    assertEquals("foo", domNode.getTextContent());
    childMap.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) StateNode(com.vaadin.client.flow.StateNode) JsonObject(elemental.json.JsonObject) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 14 with NodeMap

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

the class GwtTemplateBinderTest method testPropertyBindingTemplate.

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

Example 15 with NodeMap

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

the class InitialPropertiesHandlerTest method flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty.

@Test
public void flushPropertyUpdates_updateIsNotInProgress_flushForEechProperty() {
    Mockito.when(tree.isUpdateInProgress()).thenReturn(false);
    StateNode node = new StateNode(1, tree);
    NodeMap properties = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty property1 = properties.getProperty("foo");
    property1.setValue("bar");
    MapProperty property2 = properties.getProperty("other");
    property2.setValue("value");
    handler.nodeRegistered(node);
    Mockito.when(tree.getNode(node.getId())).thenReturn(node);
    handler.flushPropertyUpdates();
    property1.setValue("baz");
    property2.setValue("foo");
    handler.handlePropertyUpdate(property1);
    handler.handlePropertyUpdate(property2);
    AtomicInteger count = new AtomicInteger();
    FlushListener listener = () -> count.incrementAndGet();
    property1.addChangeListener(event -> Reactive.addFlushListener(listener));
    property2.addChangeListener(event -> Reactive.addFlushListener(listener));
    Reactive.flush();
    Assert.assertEquals(2, count.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FlushListener(com.vaadin.client.flow.reactive.FlushListener) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) StateNode(com.vaadin.client.flow.StateNode) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) Test(org.junit.Test)

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