-
Notifications
You must be signed in to change notification settings - Fork 167
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for returning values from JavaScript #5285
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 16 of 16 files at r1.
Reviewable status: 5 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @Legioth)
flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java, line 146 at r1 (raw file):
* A pending JavaScript result that can be sent to the client. */ public static class PendingJavaScriptInvocation
Is there a god reason to add this inside uiinternals that's already a bit too heavy?
(Would throw JavaScriptInvocation out too)
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 95 at r1 (raw file):
* or <code>null</code> to ignore errors */ default <T> void then(Class<T> targetType,
Why then
? It's straight from JavaScript and not Java that the target audience is most likely used to use.
CompletableFuture uses exceptionally(Function<Throwable,? extends T> fn)
for the exception and thenAccept(Consumer<? super T> action)
for handling the result.
This would though require that it would have a fluent api to add them.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 180 at r1 (raw file):
* or <code>null</code> to ignore errors */ void then(SerializableConsumer<JsonValue> resultHandler,
then without default implementation should probably be at the top.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 213 at r1 (raw file):
return toCompletableFuture(JsonValue.class); } }
missing new line
flow-server/src/test/java/com/vaadin/flow/component/internal/PendingJavaScriptInvocationTest.java, line 239 at r1 (raw file):
private void assertStringSuccess() { Assert.assertFalse(jsonSuccessConsumer.isCaptured());
These could have a message as now we only get expected false got true. Would help to see what was not false in the test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewable status: 5 unresolved discussions, 0 of 1 LGTMs obtained (waiting on @caalador)
flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java, line 146 at r1 (raw file):
Previously, caalador wrote…
Is there a god reason to add this inside uiinternals that's already a bit too heavy?
(Would throw JavaScriptInvocation out too)
Done.
I wouldn't want to move JavaScriptInvocation
as part of this PR since that class has been there from before and only receives quite limited changes here.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 95 at r1 (raw file):
Previously, caalador wrote…
Why
then
? It's straight from JavaScript and not Java that the target audience is most likely used to use.
CompletableFuture usesexceptionally(Function<Throwable,? extends T> fn)
for the exception andthenAccept(Consumer<? super T> action)
for handling the result.
This would though require that it would have a fluent api to add them.
CompletableFuture
uses thenXyz
because there are so many different overloads with slightly different semantics. Here, the number is quite limited so a simpler name should imho be sufficient and still clear enough.
The purpose of these methods is to avoid complexities with chaining that you'd get with a fluent API. One can use toCompletableFuture
if one wants to do something that is best expressed by chaining.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 180 at r1 (raw file):
Previously, caalador wrote…
then without default implementation should probably be at the top.
I've ordered these methods to be in an order that would logical for callers. Whether any specific method has a default implementation is only relevant for implementors, which I see as a secondary concern in this case.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 213 at r1 (raw file):
Previously, caalador wrote…
missing new line
Done. (Shouldn't Sonar automatically complain about these?)
flow-server/src/test/java/com/vaadin/flow/component/internal/PendingJavaScriptInvocationTest.java, line 239 at r1 (raw file):
Previously, caalador wrote…
These could have a message as now we only get expected false got true. Would help to see what was not false in the test.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 10 of 10 files at r2.
Reviewable status: all discussions resolved, 0 of 1 LGTMs obtained
flow-server/src/main/java/com/vaadin/flow/component/internal/UIInternals.java, line 146 at r1 (raw file):
Previously, Legioth (Leif Åstrand) wrote…
Done.
I wouldn't want to move
JavaScriptInvocation
as part of this PR since that class has been there from before and only receives quite limited changes here.
That's fine as it's its own refactor.
flow-server/src/main/java/com/vaadin/flow/component/page/PendingJavaScriptResult.java, line 213 at r1 (raw file):
Previously, Legioth (Leif Åstrand) wrote…
Done. (Shouldn't Sonar automatically complain about these?)
probably. I feel our sonar is all over the place with the checks.
flow-server/src/test/java/com/vaadin/flow/component/internal/PendingJavaScriptInvocationTest.java, line 272 at r2 (raw file):
success consuemr
typo in consumer. not that important.
*/ | ||
@FunctionalInterface | ||
@Deprecated | ||
public interface ExecutionCanceler extends Serializable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* @author Vaadin Ltd | ||
*/ | ||
@SuppressWarnings("deprecation") | ||
public interface PendingJavaScriptResult extends ExecutionCanceler { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SonarQube analysis reported 20 issues Watch the comments in this conversation to review them. Top 10 extra issuesNote: The following issues were found on lines that were not modified in the pull request. Because these issues can't be reported as line comments, they are summarized here:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 1 files at r3, 1 of 1 files at r4.
Reviewable status: 2 unresolved discussions, 1 of 1 LGTMs obtained (waiting on @Legioth)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dismissed @vaadin-bot from 2 discussions.
Reviewable status: complete! all discussions resolved, 1 of 1 LGTMs obtained
Related to #1724
This change is