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