Search in sources :

Example 31 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap 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 32 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtBasicElementBinderTest method testBindVirtualChild_withDeferredElementInShadowRoot_byIndicesPath.

public void testBindVirtualChild_withDeferredElementInShadowRoot_byIndicesPath() {
    String childId = "childElement";
    StateNode childNode = createChildNode(childId, element.getTagName());
    NodeMap properties = childNode.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    MapProperty fooProperty = properties.getProperty("foo");
    fooProperty.setValue("bar");
    WidgetUtil.setJsProperty(element, "ready", NativeFunction.create(""));
    Binder.bind(node, element);
    JsonArray path = Json.createArray();
    path.set(0, 0);
    addVirtualChild(node, childNode, NodeProperties.TEMPLATE_IN_TEMPLATE, path);
    Element shadowRoot = Browser.getDocument().createElement("div");
    List<Integer> expectedAfterBindingFeatures = Arrays.asList(NodeFeatures.POLYMER_SERVER_EVENT_HANDLERS, NodeFeatures.ELEMENT_CHILDREN);
    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)));
    WidgetUtil.setJsProperty(element, "root", shadowRoot);
    Element addressedElement = createAndAppendElementToShadowRoot(shadowRoot, childId, element.getTagName());
    // 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);
}
Also used : JsonArray(elemental.json.JsonArray) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) Element(elemental.dom.Element) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 33 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class GwtExecuteJavaScriptElementUtilsTest method testPopulateModelProperties_propertyIsDefinedAndNotUpodatable_noSyncToServer.

public void testPopulateModelProperties_propertyIsDefinedAndNotUpodatable_noSyncToServer() {
    defineProperty(element, "foo");
    WidgetUtil.setJsProperty(element, "foo", "bar");
    ExecuteJavaScriptElementUtils.populateModelProperties(node, JsCollections.array("foo"));
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    assertFalse(map.hasPropertyValue("foo"));
    assertNull(tree.syncedProperty);
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 34 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class LoadingIndicatorConfigurator method observe.

/**
 * Observes the given node for loading indicator configuration changes and
 * configures the loading indicator singleton accordingly.
 *
 * @param node
 *            the node containing the loading indicator configuration
 * @param loadingIndicator
 *            the loading indicator to configure
 */
public static void observe(StateNode node, LoadingIndicator loadingIndicator) {
    NodeMap configMap = node.getMap(NodeFeatures.LOADING_INDICATOR_CONFIGURATION);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.FIRST_DELAY_KEY, loadingIndicator::setFirstDelay, LoadingIndicatorConfigurationMap.FIRST_DELAY_DEFAULT);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.SECOND_DELAY_KEY, loadingIndicator::setSecondDelay, LoadingIndicatorConfigurationMap.SECOND_DELAY_DEFAULT);
    bindInteger(configMap, LoadingIndicatorConfigurationMap.THIRD_DELAY_KEY, loadingIndicator::setThirdDelay, LoadingIndicatorConfigurationMap.THIRD_DELAY_DEFAULT);
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 35 with NodeMap

use of com.vaadin.client.flow.nodefeature.NodeMap in project flow by vaadin.

the class SimpleElementBindingStrategy method handleDomEvent.

private void handleDomEvent(Event event, Node element, StateNode node) {
    assert element instanceof Element : "Cannot handle DOM event for a Node";
    String type = event.getType();
    NodeMap listenerMap = getDomEventListenerMap(node);
    ConstantPool constantPool = node.getTree().getRegistry().getConstantPool();
    String expressionConstantKey = (String) listenerMap.getProperty(type).getValue();
    assert expressionConstantKey != null;
    assert constantPool.has(expressionConstantKey);
    JsArray<String> dataExpressions = constantPool.get(expressionConstantKey);
    JsonObject eventData;
    if (dataExpressions.isEmpty()) {
        eventData = null;
    } else {
        eventData = Json.createObject();
        for (int i = 0; i < dataExpressions.length(); i++) {
            String expressionString = dataExpressions.get(i);
            EventDataExpression expression = getOrCreateExpression(expressionString);
            JsonValue expressionValue = expression.evaluate(event, (Element) element);
            eventData.put(expressionString, expressionValue);
        }
    }
    node.getTree().sendEventToServer(node, type, eventData);
}
Also used : ConstantPool(com.vaadin.client.flow.ConstantPool) DomElement(com.vaadin.client.flow.dom.DomElement) Element(elemental.dom.Element) JsonValue(elemental.json.JsonValue) JsonObject(elemental.json.JsonObject) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Aggregations

NodeMap (com.vaadin.client.flow.nodefeature.NodeMap)68 StateNode (com.vaadin.client.flow.StateNode)30 Element (elemental.dom.Element)21 MapProperty (com.vaadin.client.flow.nodefeature.MapProperty)20 Node (elemental.dom.Node)14 ChildSlotNode (com.vaadin.flow.template.angular.ChildSlotNode)10 ForTemplateNode (com.vaadin.flow.template.angular.ForTemplateNode)10 JsonObject (elemental.json.JsonObject)8 Test (org.junit.Test)6 DomElement (com.vaadin.client.flow.dom.DomElement)5 UpdatableModelProperties (com.vaadin.client.flow.model.UpdatableModelProperties)4 NodeList (com.vaadin.client.flow.nodefeature.NodeList)4 DomNode (com.vaadin.client.flow.dom.DomNode)3 NodeFeature (com.vaadin.client.flow.nodefeature.NodeFeature)3 Computation (com.vaadin.client.flow.reactive.Computation)3 NativeFunction (com.vaadin.client.flow.util.NativeFunction)3 JsonValue (elemental.json.JsonValue)3 Command (com.vaadin.client.Command)2 ConstantPool (com.vaadin.client.flow.ConstantPool)2 JsArray (com.vaadin.client.flow.collection.JsArray)2