Search in sources :

Example 26 with NodeMap

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

the class StateNode method getMap.

/**
 * Gets the node map with the given id. Creates a new map if one doesn't
 * already exist.
 *
 * @param id
 *            the id of the map
 * @return the map with the given id
 */
public NodeMap getMap(int id) {
    Double key = Double.valueOf(id);
    NodeFeature feature = features.get(key);
    if (feature == null) {
        feature = new NodeMap(id, this);
        features.set(key, feature);
    }
    assert feature instanceof NodeMap;
    return (NodeMap) feature;
}
Also used : NodeFeature(com.vaadin.client.flow.nodefeature.NodeFeature) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 27 with NodeMap

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

the class PolymerUtils method getPropertiesNotificationPath.

private static String getPropertiesNotificationPath(StateNode currentNode) {
    String propertyNameInTheMap = null;
    NodeMap map = currentNode.getParent().getMap(NodeFeatures.ELEMENT_PROPERTIES);
    JsArray<String> propertyNames = map.getPropertyNames();
    for (int i = 0; i < propertyNames.length(); i++) {
        String propertyName = propertyNames.get(i);
        if (currentNode.equals(map.getProperty(propertyName).getValue())) {
            propertyNameInTheMap = propertyName;
            break;
        }
    }
    if (propertyNameInTheMap == null) {
        return null;
    }
    return propertyNameInTheMap;
}
Also used : NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 28 with NodeMap

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

the class PolymerUtils method registerChangeHandlers.

private static void registerChangeHandlers(StateNode node, NodeFeature feature, JsonValue value) {
    JsArray<EventRemover> registrations = JsCollections.array();
    if (node.hasFeature(NodeFeatures.ELEMENT_PROPERTIES)) {
        assert feature instanceof NodeMap : "Received an inconsistent NodeFeature for a node that has a ELEMENT_PROPERTIES feature. It should be NodeMap, but it is: " + feature;
        NodeMap map = (NodeMap) feature;
        registerPropertyChangeHandlers(value, registrations, map);
        registerPropertyAddHandler(value, registrations, map);
    } else if (node.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
        assert feature instanceof NodeList : "Received an inconsistent NodeFeature for a node that has a TEMPLATE_MODELLIST feature. It should be NodeList, but it is: " + feature;
        NodeList list = (NodeList) feature;
        registrations.push(list.addSpliceListener(event -> handleListChange(event, value)));
    }
    assert !registrations.isEmpty() : "Node should have ELEMENT_PROPERTIES or TEMPLATE_MODELLIST feature";
    registrations.push(node.addUnregisterListener(event -> registrations.forEach(EventRemover::remove)));
}
Also used : ShadowRoot(elemental.dom.ShadowRoot) JsWeakMap(com.vaadin.client.flow.collection.JsWeakMap) Reactive(com.vaadin.client.flow.reactive.Reactive) DomApi(com.vaadin.client.flow.dom.DomApi) Json(elemental.json.Json) NodeProperties(com.vaadin.flow.internal.nodefeature.NodeProperties) JsonArray(elemental.json.JsonArray) ListSpliceEvent(com.vaadin.client.flow.nodefeature.ListSpliceEvent) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap) NodeFeatures(com.vaadin.flow.internal.nodefeature.NodeFeatures) StateNode(com.vaadin.client.flow.StateNode) MapProperty(com.vaadin.client.flow.nodefeature.MapProperty) HTMLCollection(elemental.html.HTMLCollection) JsonValue(elemental.json.JsonValue) NodeFeature(com.vaadin.client.flow.nodefeature.NodeFeature) NodeList(com.vaadin.client.flow.nodefeature.NodeList) EventRemover(elemental.events.EventRemover) JsSet(com.vaadin.client.flow.collection.JsSet) Node(elemental.dom.Node) JsCollections(com.vaadin.client.flow.collection.JsCollections) Element(elemental.dom.Element) JsonObject(elemental.json.JsonObject) JsArray(com.vaadin.client.flow.collection.JsArray) EventRemover(elemental.events.EventRemover) NodeList(com.vaadin.client.flow.nodefeature.NodeList) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 29 with NodeMap

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

the class GwtBasicElementBinderTest method testPropertyValueHasPrototypeMethods.

public void testPropertyValueHasPrototypeMethods() {
    NodeMap map = new NodeMap(0, new StateNode(0, new StateTree(null)));
    JsonObject object = Json.createObject();
    object.put("name", "bar");
    map.getProperty("foo").setValue(object);
    assertTrue(map.hasPropertyValue("foo"));
    String toString = getToString(map.getProperty("foo").getValue());
    assertEquals("[object Object]", toString);
}
Also used : JsonObject(elemental.json.JsonObject) NodeMap(com.vaadin.client.flow.nodefeature.NodeMap)

Example 30 with NodeMap

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

the class GwtExecuteJavaScriptElementUtilsTest method testPopulateModelProperties_elementIsNotReadyAndPropertyIsNotDefined_addIntoPropertiesMapAfterElementBecomesReady.

public void testPopulateModelProperties_elementIsNotReadyAndPropertyIsNotDefined_addIntoPropertiesMapAfterElementBecomesReady() {
    node.setDomNode(null);
    mockWhenDefined(element);
    ExecuteJavaScriptElementUtils.populateModelProperties(node, JsCollections.array("bar"));
    NodeMap map = node.getMap(NodeFeatures.ELEMENT_PROPERTIES);
    assertFalse(map.hasPropertyValue("bar"));
    node.setDomNode(element);
    runWhenDefined(element);
    Reactive.flush();
    assertTrue(map.hasPropertyValue("bar"));
}
Also used : 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