Search in sources :

Example 56 with NodeMap

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

the class GwtBasicElementBinderTest method testBindVirtualChild_withCorrespondingElementInShadowRoot_byId.

public void testBindVirtualChild_withCorrespondingElementInShadowRoot_byId() {
    Element shadowRootElement = addShadowRootElement(element);
    String childId = "childElement";
    StateNode childNode = createChildNode(childId, element.getTagName());
    NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty fooProperty = properties.getProperty("foo");
    fooProperty.setValue("bar");
    Binder.bind(node, element);
    addVirtualChild(node, childNode, NodeProperties.INJECT_BY_ID, Json.create(childId));
    Element addressedElement = createAndAppendElementToShadowRoot(shadowRootElement, childId, element.getTagName());
    List<Integer> expectedAfterBindingFeatures = Arrays.asList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN);
    expectedAfterBindingFeatures.forEach(notExpectedFeature -> assertFalse("Child node should not have any features from list " + expectedAfterBindingFeatures + " before binding, but got feature " + notExpectedFeature, childNode.hasFeature(notExpectedFeature)));
    Reactive.flush();
    expectedAfterBindingFeatures.forEach(expectedFeature -> assertTrue("Child node should have all features from list " + expectedAfterBindingFeatures + " before binding, but missing feature " + expectedFeature, childNode.hasFeature(expectedFeature)));
    // nothing has changed: no new child
    assertEquals("No new child should be added to the element after attach", 0, element.getChildElementCount());
    assertEquals("No new child should be added to the shadow root after attach", 1, shadowRootElement.getChildElementCount());
    Element childElement = shadowRootElement.getFirstElementChild();
    assertSame("Existing element should be the same as element in the StateNode object", addressedElement, childElement);
}
Also used : Element(elemental.dom.Element) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 57 with NodeMap

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

the class GwtBasicElementBinderTest method setVisible.

private void setVisible(boolean visible) {
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_DATA);
    MapProperty visibility = map.getProperty(NodeProperties.VISIBLE);
    visibility.setValue(visible);
}
Also used : MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 58 with NodeMap

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

the class GwtBasicElementBinderTest method testRemoveStyles.

public void testRemoveStyles() {
    polyfillStyleSetProperty(element);
    Binder.bind(node, element);
    NodeMap styleMap = node.getMap(NodeFeatures.ELEMENT_STYLE_PROPERTIES);
    styleMap.getProperty("background").setValue("blue");
    styleMap.getProperty("color").setValue("white");
    Reactive.flush();
    assertEquals("blue", element.getStyle().getPropertyValue("background"));
    assertEquals("white", element.getStyle().getColor());
    styleMap.getProperty("color").removeValue();
    Reactive.flush();
    assertEquals("blue", element.getStyle().getPropertyValue("background"));
    assertEquals("", element.getStyle().getColor());
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 59 with NodeMap

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

the class SimpleElementBindingStrategy method bindMap.

private EventRemover bindMap(int featureId, PropertyUser user, JsMap<String, Computation> bindings, StateNode node) {
    NodeMap map = node.getMap(featureId);
    map.forEachProperty((property, name) -> bindProperty(user, property, bindings).recompute());
    return map.addPropertyAddListener(e -> bindProperty(user, e.getProperty(), bindings));
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 60 with NodeMap

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

the class SimpleElementBindingStrategy method bindVisibility.

private EventRemover bindVisibility(JsArray<EventRemover> listeners, BindingContext context, JsArray<JsMap<String, Computation>> computationsCollection, BinderContext nodeFactory) {
    assert context.htmlNode instanceof Element : "The HTML node for the StateNode with id=" + context.node.getId() + " is not an Element";
    NodeMap visibilityData = context.node.getMap(NodeFeatures.ELEMENT_DATA);
    visibilityData.getProperty(NodeProperties.VISIBILITY_BOUND_PROPERTY).setValue(isVisible(context.node));
    updateVisibility(listeners, context, computationsCollection, nodeFactory);
    return context.node.getMap(NodeFeatures.ELEMENT_DATA).getProperty(NodeProperties.VISIBLE).addChangeListener(event -> updateVisibility(listeners, context, computationsCollection, nodeFactory));
}
Also used : DomElement(com.vaadin.client.flow.dom.DomElement) Element(elemental.dom.Element) 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