Skip to content

Commit

Permalink
Merge branch 'master' into 'ccdm'
Browse files Browse the repository at this point in the history
  • Loading branch information
qtdzz committed Nov 20, 2019
2 parents 5f8a8bd + 050e078 commit 1c5fe4f
Show file tree
Hide file tree
Showing 144 changed files with 3,368 additions and 46,749 deletions.
18 changes: 9 additions & 9 deletions drivers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,32 @@
<root>
<windows>
<driver id="googlechrome">
<version id="77.0.3865.40">
<version id="78.0.3904.70">
<bitrate thirtytwobit="true" sixtyfourbit="true">
<filelocation>https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_win32.zip</filelocation>
<hash>c367947ec475e436e34f3f9c4864ae3659867c6e</hash>
<filelocation>https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_win32.zip</filelocation>
<hash>26705e683632c6e1f9c62179b6143b409f4d7681</hash>
<hashtype>sha1</hashtype>
</bitrate>
</version>
</driver>
</windows>
<linux>
<driver id="googlechrome">
<version id="77.0.3865.40">
<version id="78.0.3904.70">
<bitrate sixtyfourbit="true">
<filelocation>https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_linux64.zip</filelocation>
<hash>1776fe8449489fa98e4fe80255ed3874f94d0dee</hash>
<filelocation>https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_linux64.zip</filelocation>
<hash>63e13e5f0df96af1cc3a2006c00b2f1871b62caf</hash>
<hashtype>sha1</hashtype>
</bitrate>
</version>
</driver>
</linux>
<osx>
<driver id="googlechrome">
<version id="77.0.3865.40">
<version id="78.0.3904.70">
<bitrate sixtyfourbit="true">
<filelocation>https://chromedriver.storage.googleapis.com/77.0.3865.40/chromedriver_mac64.zip</filelocation>
<hash>bc5d502044c86fbba20614df317cc2194d19aa86</hash>
<filelocation>https://chromedriver.storage.googleapis.com/78.0.3904.70/chromedriver_mac64.zip</filelocation>
<hash>ce06a7d3a9d18b3d054d3b4c3c32d2cd74e81a91</hash>
<hashtype>sha1</hashtype>
</bitrate>
</version>
Expand Down
5 changes: 5 additions & 0 deletions flow-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<artifactId>flow-html-components</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-server-production-mode</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.vaadin</groupId>
<artifactId>flow-html-components-testbench</artifactId>
Expand Down
1 change: 1 addition & 0 deletions flow-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
<style>${gwt.module.style}</style>
<htmlunit>FF38</htmlunit>
<testTimeOut>300</testTimeOut>
<extraJvmArgs>-Xmx512m -Dvaadin.enableDevServer=false</extraJvmArgs>
</configuration>
</plugin>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -771,13 +771,14 @@ private static native void runPromiseExpression(String expression,
/*-{
try {
var promise = [email protected]::get(*)();
if ( !(promise instanceof Promise )){
if ( !(promise instanceof $wnd.Promise )){
throw new Error('The expression "'+expression+'" result is not a Promise.');
}
promise.then( function(result) { [email protected]::run(*)(); } ,
function(error) { [email protected]::run(*)(); } );
function(error) { console.error(error); [email protected]::run(*)(); } );
}
catch(error) {
console.error(error);
[email protected]::run(*)();
}
}-*/;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import com.vaadin.client.Console;
import com.vaadin.client.Registry;
import com.vaadin.client.UILifecycle;
import com.vaadin.client.UILifecycle.UIState;
import com.vaadin.client.WidgetUtil;
import com.vaadin.client.communication.AtmospherePushConnection.AtmosphereResponse;
Expand Down Expand Up @@ -297,7 +298,10 @@ protected void updateDialog() {
*/
protected final void giveUp() {
reconnectionCause = null;
endRequest();

if (registry.getRequestResponseTracker().hasActiveRequest()) {
endRequest();
}

stopDialogTimer();
if (!isDialogVisible()) {
Expand Down Expand Up @@ -468,7 +472,12 @@ protected void handleUnauthorized(XhrConnectionError xhrConnectionError) {
private void stopApplication() {
// Consider application not running any more and prevent all
// future requests
registry.getUILifecycle().setState(UIState.TERMINATED);

UILifecycle uiLifecycle = registry.getUILifecycle();

if (uiLifecycle.getState() != UIState.TERMINATED) {
uiLifecycle.setState(UIState.TERMINATED);
}
}

private void handleUnrecoverableCommunicationError(String details,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.google.gwt.core.client.Duration;
import com.google.gwt.core.client.Scheduler;
import com.google.gwt.user.client.Timer;

import com.vaadin.client.Command;
import com.vaadin.client.Console;
import com.vaadin.client.DependencyLoader;
Expand Down Expand Up @@ -190,8 +191,15 @@ public void handleMessage(final ValueMap json) {
"The json to handle cannot be null");
}
if (getServerId(json) == -1) {
Console.error("Response didn't contain a server id. "
+ "Please verify that the server is up-to-date and that the response data has not been modified in transmission.");

ValueMap meta = json.getValueMap("meta");

// Log the error only if session didn't expire.
if (meta == null
|| !meta.containsKey(JsonConstants.META_SESSION_EXPIRED)) {
Console.error("Response didn't contain a server id. "
+ "Please verify that the server is up-to-date and that the response data has not been modified in transmission.");
}
}

UIState state = registry.getUILifecycle().getState();
Expand Down Expand Up @@ -502,7 +510,7 @@ private boolean isResynchronize(ValueMap json) {

private boolean isResponse(ValueMap json) {
ValueMap meta = json.getValueMap("meta");
if (meta == null || !meta.containsKey("async")) {
if (meta == null || !meta.containsKey(JsonConstants.META_ASYNC)) {
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,21 @@ public void sendEventMessage(int nodeId, String eventType,
* the event handler method name to execute on the server side
* @param argsArray
* the arguments array for the method
* @param promiseId
* the promise id to use for getting the result back, or -1 if no
* result is expected
*/
public void sendTemplateEventMessage(StateNode node, String methodName,
JsonArray argsArray) {
JsonArray argsArray, int promiseId) {
JsonObject message = Json.createObject();
message.put(JsonConstants.RPC_TYPE,
JsonConstants.RPC_PUBLISHED_SERVER_EVENT_HANDLER);
message.put(JsonConstants.RPC_NODE, node.getId());
message.put(JsonConstants.RPC_TEMPLATE_EVENT_METHOD_NAME, methodName);
message.put(JsonConstants.RPC_TEMPLATE_EVENT_ARGS, argsArray);
if (promiseId != -1) {
message.put(JsonConstants.RPC_TEMPLATE_EVENT_PROMISE, promiseId);
}
sendMessage(message);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,16 @@ public void sendNodePropertySyncToServer(MapProperty property) {
* the method name
* @param argsArray
* the arguments array for the method
* @param promiseId
* the promise id to use for getting the result back, or -1 if no
* result is expected
*/
public void sendTemplateEventToServer(StateNode node, String methodName,
JsArray<?> argsArray) {
JsArray<?> argsArray, int promiseId) {
if (isValidNode(node)) {
JsonArray array = WidgetUtil.crazyJsCast(argsArray);
registry.getServerConnector().sendTemplateEventMessage(node,
methodName, array);
methodName, array, promiseId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ private ServerEventHandlerBinder() {
public static EventRemover bindServerEventHandlerNames(Element element,
StateNode node) {
return bindServerEventHandlerNames(() -> ServerEventObject.get(element),
node, NodeFeatures.CLIENT_DELEGATE_HANDLERS);
node, NodeFeatures.CLIENT_DELEGATE_HANDLERS, true);
}

/**
Expand All @@ -67,11 +67,15 @@ public static EventRemover bindServerEventHandlerNames(Element element,
* the state node containing the feature
* @param featureId
* the feature id which contains event handler methods
* @param returnValue
* <code>true</code> if the handler should return a promise that
* will reflect the server-side result; <code>false</code> to not
* return any value
* @return a handle which can be used to remove the listener for the feature
*/
public static EventRemover bindServerEventHandlerNames(
Supplier<ServerEventObject> objectProvider, StateNode node,
int featureId) {
int featureId, boolean returnValue) {
NodeList serverEventHandlerNamesList = node.getList(featureId);

if (serverEventHandlerNamesList.length() > 0) {
Expand All @@ -80,7 +84,7 @@ public static EventRemover bindServerEventHandlerNames(
for (int i = 0; i < serverEventHandlerNamesList.length(); i++) {
String serverEventHandlerName = (String) serverEventHandlerNamesList
.get(i);
object.defineMethod(serverEventHandlerName, node);
object.defineMethod(serverEventHandlerName, node, returnValue);
}
}

Expand All @@ -94,7 +98,8 @@ public static EventRemover bindServerEventHandlerNames(

JsArray<?> add = e.getAdd();
for (int i = 0; i < add.length(); i++) {
serverObject.defineMethod((String) add.get(i), node);
serverObject.defineMethod((String) add.get(i), node,
returnValue);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.vaadin.client.flow.binding;


import jsinterop.annotations.JsFunction;

import com.google.gwt.core.client.JavaScriptObject;
Expand All @@ -28,6 +27,7 @@
import com.vaadin.client.flow.collection.JsMap;
import com.vaadin.client.flow.util.NativeFunction;
import com.vaadin.flow.internal.nodefeature.NodeFeatures;
import com.vaadin.flow.shared.JsonConstants;

import elemental.dom.Element;
import elemental.dom.Node;
Expand All @@ -46,6 +46,8 @@ public final class ServerEventObject extends JavaScriptObject {
private static final String NODE_ID = "nodeId";
private static final String EVENT_PREFIX = "event";

private static final String PROMISE_CALLBACK_NAME = JsonConstants.RPC_PROMISE_CALLBACK_NAME;

/**
* Callback interface for an event data expression parsed using new
* Function() in JavaScript.
Expand Down Expand Up @@ -76,6 +78,31 @@ private interface ServerEventDataExpression {
protected ServerEventObject() {
}

private native void initPromiseHandler()
/*-{
var name = @ServerEventObject::PROMISE_CALLBACK_NAME
// Use defineProperty to make it non-enumerable
Object.defineProperty(this, name, {
value: function(promiseId, success, value) {
var promise = this[name].promises[promiseId];
// undefined if client-side node was recreated after execution was scheduled
if (promise !== undefined) {
delete this[name].promises[promiseId];
if (success) {
// Resolve
promise[0](value);
} else {
// Reject
promise[1](Error("Something went wrong. Check server-side logs for more information."));
}
}
}
});
this[name].promises = [];
}-*/;

/**
* Defines a method with the given name to be a callback to the server for
* the given state node.
Expand All @@ -88,8 +115,13 @@ protected ServerEventObject() {
* @param node
* the node to use as an identifier when sending an event to the
* server
* @param returnPromise
* <code>true</code> if the handler should return a promise that
* will reflect the server-side result; <code>false</code> to not
* return any value
*/
public native void defineMethod(String methodName, StateNode node)
public native void defineMethod(String methodName, StateNode node,
boolean returnPromise)
/*-{
this[methodName] = $entry(function(eventParameter) {
var prototype = Object.getPrototypeOf(this);
Expand All @@ -102,7 +134,24 @@ public native void defineMethod(String methodName, StateNode node)
if(args === null) {
args = Array.prototype.slice.call(arguments);
}
[email protected]::sendTemplateEventToServer(*)(node, methodName, args);
var returnValue;
var promiseId = -1;
if (returnPromise) {
var promises = this[@ServerEventObject::PROMISE_CALLBACK_NAME].promises;
promiseId = promises.length;
returnValue = new Promise(function(resolve, reject) {
// Store each callback for later use
promises[promiseId] = [resolve, reject];
});
}
[email protected]::sendTemplateEventToServer(*)(node, methodName, args, promiseId);
return returnValue;
});
}-*/;

Expand Down Expand Up @@ -230,6 +279,7 @@ public static ServerEventObject get(Element element) {
.crazyJsoCast(WidgetUtil.getJsProperty(element, "$server"));
if (serverObject == null) {
serverObject = (ServerEventObject) JavaScriptObject.createObject();
serverObject.initPromiseHandler();
WidgetUtil.setJsProperty(element, "$server", serverObject);
}
return serverObject;
Expand Down
Loading

0 comments on commit 1c5fe4f

Please sign in to comment.