Search in sources :

Example 1 with UpdatableModelProperties

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());
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 2 with UpdatableModelProperties

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);
    }
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties)

Example 3 with UpdatableModelProperties

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));
}
Also used : SchedulerImpl(com.google.gwt.core.client.impl.SchedulerImpl) UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Example 4 with UpdatableModelProperties

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"));
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Example 5 with UpdatableModelProperties

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"));
}
Also used : UpdatableModelProperties(com.vaadin.client.flow.model.UpdatableModelProperties) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty)

Aggregations

UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)9 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)5 NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)3 SchedulerImpl (com.google.gwt.core.client.impl.SchedulerImpl)1 StateNode (com.vaadin.client.flow.StateNode)1 JsonObject (elemental.json.JsonObject)1