use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtExecuteJavaScriptElementUtilsTest method testPopulateModelProperties_propertyIsDefined_syncToServer.
public void testPopulateModelProperties_propertyIsDefined_syncToServer() {
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);
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 ExecuteJavaScriptElementUtils method registerUpdatableModelProperties.
/**
* Register the updatable model properties of the {@code node}.
* <p>
* Only updates for the properties from the {@code properties} array will be
* sent to the server without explicit synchronization. The
* {@code properties} array includes all properties that are allowed to be
* updated (including sub properties).
*
* @param node
* the node whose updatable properties should be registered
* @param properties
* all updatable model properties
*/
public static void registerUpdatableModelProperties(StateNode node, JsArray<String> properties) {
if (!properties.isEmpty()) {
UpdatableModelProperties data = new UpdatableModelProperties(properties);
node.setNodeData(data);
}
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtPolymerModelTest method testInitialUpdateModelProperty_propertyIsUpdatableAndSchedulerIsNotExecuted_propertyIsNotSync.
public void testInitialUpdateModelProperty_propertyIsUpdatableAndSchedulerIsNotExecuted_propertyIsNotSync() {
addMockMethods(element);
String propertyName = "black";
String propertyValue = "coffee";
setModelProperty(node, propertyName, propertyValue);
initScheduler(new SchedulerImpl() {
@Override
public void scheduleDeferred(ScheduledCommand cmd) {
}
});
node.setNodeData(new UpdatableModelProperties(JsCollections.array("black")));
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", propertyValue, WidgetUtil.getJsProperty(element, propertyName));
MapProperty property = node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty(propertyName);
assertEquals(propertyValue, property.getValue());
assertFalse(tree.synchronizedProperties.has(node));
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtPolymerModelTest method testLatePolymerInit.
public void testLatePolymerInit() {
emulatePolymerNotLoaded();
addMockMethods(element);
String propertyName = "black";
String propertyValue = "coffee";
setModelProperty(node, propertyName, propertyValue);
node.setNodeData(new UpdatableModelProperties(JsCollections.array("black")));
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));
assertEquals("`_propertiesChanged` should be triggered exactly once", 1.0, WidgetUtil.getJsProperty(element, "propertiesChangedCallCount"));
assertEquals("Exactly one `whenDefined.then` callback should be called after element was initialized", 1.0, WidgetUtil.getJsProperty(element, "callbackCallCount"));
}
use of com.vaadin.client.flow.model.UpdatableModelProperties in project flow by vaadin.
the class GwtPolymerModelTest method testUpdateModelSubProperty_subpropertyIsUpdatableAndIsNotSetFromServer_subpropertyIsSync.
public void testUpdateModelSubProperty_subpropertyIsUpdatableAndIsNotSetFromServer_subpropertyIsSync() {
addMockMethods(element);
setModelProperty(node, "bar", modelNode);
node.setNodeData(new UpdatableModelProperties(JsCollections.array("bar.foo")));
Binder.bind(node, element);
Reactive.flush();
String newSubPropertyValue = "baz";
PolymerUtils.setProperty(element, "bar.foo", "baz");
emulatePolymerPropertyChange(element, "bar.foo", "baz");
Reactive.flush();
assertEquals("Expected to have an object 'bar' with a property named 'foo'" + " updated from client side", newSubPropertyValue, WidgetUtil.getJsProperty(WidgetUtil.getJsProperty(element, "bar"), "foo"));
MapProperty property = modelNode.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo");
assertEquals(newSubPropertyValue, property.getValue());
assertEquals(newSubPropertyValue, tree.synchronizedProperties.get(modelNode).get("foo"));
}
Aggregations