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