use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtBasicElementBinderTest method testVirtualChild.
public void testVirtualChild() {
Binder.bind(node, element);
StateNode childNode = createChildNode("child");
NodeMap elementData = childNode.getMap(NodeFeatures.ELEMENT_DATA);
JsonObject object = Json.createObject();
object.put(NodeProperties.TYPE, NodeProperties.IN_MEMORY_CHILD);
elementData.getProperty(NodeProperties.PAYLOAD).setValue(object);
NodeList virtialChildren = node.getList(NodeFeatures.VIRTUAL_CHILDREN);
virtialChildren.add(0, childNode);
Reactive.flush();
assertEquals(element.getChildElementCount(), 0);
Element childElement = (Element) childNode.getDomNode();
assertEquals("SPAN", childElement.getTagName());
assertEquals("child", childElement.getId());
}
use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.
the class GwtBasicElementBinderTest method testBindVirtualChild_withDeferredElementInShadowRoot_byId.
public void testBindVirtualChild_withDeferredElementInShadowRoot_byId() {
String childId = "childElement";
String tag = element.getTagName();
StateNode childNode = createChildNode(childId, tag);
NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
MapProperty fooProperty = properties.getProperty("foo");
fooProperty.setValue("bar");
addVirtualChild(node, childNode, NodeProperties.INJECT_BY_ID, Json.create(childId));
Element shadowRoot = addShadowRootElement(element);
List<Integer> expectedAfterBindingFeatures = Arrays.asList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN);
Binder.bind(node, element);
Reactive.flush();
expectedAfterBindingFeatures.forEach(notExpectedFeature -> assertFalse("Child node should not have any features from list " + expectedAfterBindingFeatures + " before binding, but got feature " + notExpectedFeature, childNode.hasFeature(notExpectedFeature)));
Element addressedElement = createAndAppendElementToShadowRoot(shadowRoot, childId, tag);
// add flush listener which register the property to revert its initial
// value back if it has been changed during binding "from the client
// side" and do update the property emulating client side update
// The property value should be reverted back in the end
Reactive.addFlushListener(() -> {
tree.getRegistry().getInitialPropertiesHandler().handlePropertyUpdate(fooProperty);
fooProperty.setValue("baz");
});
PolymerUtils.fireReadyEvent(element);
// the property value should be the same as initially
assertEquals("bar", fooProperty.getValue());
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, shadowRoot.getChildElementCount());
Element childElement = shadowRoot.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 TextBindingStrategy method bind.
@Override
public void bind(StateNode stateNode, Text htmlNode, BinderContext nodeFactory) {
assert stateNode.hasFeature(NodeFeatures.TEXT_NODE);
if (BOUND.has(stateNode)) {
return;
}
BOUND.set(stateNode, true);
NodeMap textMap = stateNode.getMap(NodeFeatures.TEXT_NODE);
MapProperty textProperty = textMap.getProperty(NodeProperties.TEXT);
Computation computation = Reactive.runWhenDependenciesChange(() -> htmlNode.setData((String) textProperty.getValue()));
stateNode.addUnregisterListener(e -> unbind(stateNode, computation));
}
Aggregations