use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtPolymerModelTest method testInitialUpdateModelProperty_propertyIsUpdatable_propertyIsSynced.
public void testInitialUpdateModelProperty_propertyIsUpdatable_propertyIsSynced() {
addMockMethods(element);
String propertyName = "black";
String propertyValue = "coffee";
setModelProperty(node, propertyName, propertyValue);
node.setNodeData(new UpdatableModelProperties(JsCollections.array(propertyName)));
Binder.bind(node, element);
Reactive.flush();
assertEquals("Expected to have property with name " + propertyName + " defined after initial binding", propertyValue, WidgetUtil.getJsProperty(element, propertyName));
String newPropertyValue = "bubblegum";
emulatePolymerPropertyChange(element, propertyName, newPropertyValue);
Reactive.flush();
assertEquals("Expected to have property with name " + propertyName + " updated from client side", newPropertyValue, WidgetUtil.getJsProperty(element, propertyName));
MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty(propertyName);
assertEquals(newPropertyValue, property.getValue());
assertEquals(newPropertyValue, tree.synchronizedProperties.get(node).get(propertyName));
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class ExecuteJavaScriptElementUtils method populateModelProperty.
private static void populateModelProperty(StateNode node, NodeMap map, String property) {
if (!isPropertyDefined(node.getDomNode(), property)) {
if (!map.hasPropertyValue(property)) {
map.getProperty(property).setValue(null);
}
} else {
UpdatableModelProperties updatableProperties = node.getNodeData(UpdatableModelProperties.class);
if (updatableProperties == null || !updatableProperties.isUpdatableProperty(property)) {
return;
}
map.getProperty(property).syncToServer(WidgetUtil.getJsProperty(node.getDomNode(), property));
}
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method testPopulateModelProperties_elementIsNotReadyAndPropertyIsDefined_syncToServerWhenElementBecomesReady.
public void testPopulateModelProperties_elementIsNotReadyAndPropertyIsDefined_syncToServerWhenElementBecomesReady() {
node.setDomNode(null);
mockWhenDefined(element);
defineProperty(element, "foo");
node.setNodeData(new UpdatableModelProperties(JsCollections.array("foo")));
WidgetUtil.setJsProperty(element, "foo", "bar");
ExecuteJavaScriptElementUtils.populateModelProperties(node, JsCollections.array("foo"));
NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
assertFalse(map.hasPropertyValue("foo"));
node.setDomNode(element);
runWhenDefined(element);
Reactive.flush();
assertTrue(map.hasPropertyValue("foo"));
assertEquals("bar", tree.syncedProperty.getValue());
assertEquals("foo", tree.syncedProperty.getName());
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class SimpleElementBindingStrategy method handlePropertyChange.
private void handlePropertyChange(String fullPropertyName, Supplier<Object> valueProvider, StateNode node) {
UpdatableModelProperties updatableProperties = node.getNodeData(UpdatableModelProperties.class);
if (updatableProperties == null || !updatableProperties.isUpdatableProperty(fullPropertyName)) {
// collection of updatable properties
return;
}
// This is not the property value itself, its a parent node of the
// property
String[] subProperties = fullPropertyName.split("\\.");
StateNode model = node;
MapProperty mapProperty = null;
int i = 0;
int size = subProperties.length;
for (String subProperty : subProperties) {
NodeMap elementProperties = model.getMap(NodeFeatures.ELEMENT_PROPERTIES);
if (!elementProperties.hasPropertyValue(subProperty) && i < size - 1) {
Console.debug("Ignoring property change for property '" + fullPropertyName + "' which isn't defined from server");
return;
}
mapProperty = elementProperties.getProperty(subProperty);
if (mapProperty.getValue() instanceof StateNode) {
model = (StateNode) mapProperty.getValue();
}
i++;
}
if (mapProperty.getValue() instanceof StateNode) {
// Don't send to the server updates for list nodes
StateNode nodeValue = (StateNode) mapProperty.getValue();
JsonObject obj = WidgetUtil.crazyJsCast(valueProvider.get());
if (!obj.hasKey("nodeId") || nodeValue.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
return;
}
}
mapProperty.syncToServer(valueProvider.get());
}
Aggregations