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;
}
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;
}
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)));
}
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);
}
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"));
}
Aggregations