use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class SimpleElementBindingStrategy method setSubProperties.
private void setSubProperties(Element htmlNode, MapProperty property, String path) {
String newPath = path.isEmpty() ? property.getName() : path + "." + property.getName();
NativeFunction setValueFunction = NativeFunction.create("path", "value", "this.set(path, value)");
if (property.getValue() instanceof StateNode) {
StateNode subNode = (StateNode) property.getValue();
if (subNode.hasFeature(NodeFeatures.TEMPLATE_MODELLIST)) {
setValueFunction.call(htmlNode, newPath, PolymerUtils.convertToJson(subNode));
addModelListChangeListener(htmlNode, subNode.getList(NodeFeatures.TEMPLATE_MODELLIST), newPath);
} else {
NativeFunction function = NativeFunction.create("path", "value", "this.set(path, {})");
function.call(htmlNode, newPath);
bindModelProperties(subNode, htmlNode, newPath);
}
} else {
setValueFunction.call(htmlNode, newPath, property.getValue());
}
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class GwtMultipleBindingTest method testBindModelPropertiesDoubleBind.
public void testBindModelPropertiesDoubleBind() {
String name = "custom-div";
Element element = Browser.getDocument().createElement(name);
WidgetUtil.setJsProperty(element, "localName", name);
initPolymer(element);
NativeFunction function = NativeFunction.create("");
WidgetUtil.setJsProperty(element, "set", function);
Binder.bind(node, element);
node.getMap(NodeFeatures.ELEMENT_PROPERTIES).getProperty("foo").setValue("bar");
Reactive.flush();
node.setBound();
Binder.bind(node, element);
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class SimpleElementBindingStrategy method attachShadow.
private void attachShadow(BindingContext context) {
NodeMap map = context.node.getMap(NodeFeatures.SHADOW_ROOT_DATA);
StateNode shadowRootNode = (StateNode) map.getProperty(NodeProperties.SHADOW_ROOT).getValue();
if (shadowRootNode != null) {
NativeFunction function = NativeFunction.create("element", "if ( element.shadowRoot ) { return element.shadowRoot; } " + "else { return element.attachShadow({'mode' : 'open'});}");
Node shadowRoot = (Node) function.call(null, context.htmlNode);
if (shadowRootNode.getDomNode() == null) {
shadowRootNode.setDomNode(shadowRoot);
}
BindingContext newContext = new BindingContext(shadowRootNode, shadowRoot, context.binderContext);
bindChildren(newContext);
}
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class ExecuteJavaScriptProcessor method invoke.
/**
* Executes the actual invocation. This method is protected instead of
* private for testing purposes.
*
* @param parameterNamesAndCode
* an array consisting of parameter names followed by the
* JavaScript expression to execute
* @param parameters
* an array of parameter values
* @param nodeParameters
* the node parameters
*/
protected void invoke(String[] parameterNamesAndCode, JsArray<Object> parameters, JsMap<Object, StateNode> nodeParameters) {
assert parameterNamesAndCode.length == parameters.length() + 1;
try {
NativeFunction function = new NativeFunction(parameterNamesAndCode);
function.apply(getContextExecutionObject(nodeParameters, () -> {
if (!registry.getUILifecycle().isTerminated()) {
registry.getUILifecycle().setState(UIState.TERMINATED);
}
}), parameters);
} catch (Exception exception) {
Console.reportStacktrace(exception);
Console.error("Exception is thrown during JavaScript execution. Stacktrace will be dumped separately.");
if (!registry.getApplicationConfiguration().isProductionMode()) {
StringBuilder codeBuilder = new StringBuilder("[");
String delimiter = "";
for (String snippet : parameterNamesAndCode) {
codeBuilder.append(delimiter).append(snippet);
delimiter = ", ";
}
codeBuilder.append("]");
String code = codeBuilder.toString();
if (code.charAt(0) == '[') {
code = code.substring(1);
}
if (code.charAt(code.length() - 1) == ']') {
code = code.substring(0, code.length() - 1);
}
Console.error("The error has occurred in the JS code: '" + code + "'");
}
}
}
use of com.vaadin.client.flow.util.NativeFunction in project flow by vaadin.
the class ApplicationConnection method addDomSetListener.
private void addDomSetListener(int nodeId, JavaScriptObject callback) {
registry.getStateTree().getNode(nodeId).addDomNodeSetListener(node -> {
if (nodeId == node.getId()) {
NativeFunction function = NativeFunction.create("callback", "callback();");
function.call(null, callback);
return true;
}
return false;
});
}
Aggregations