Skip to content
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

Merged
merged 1 commit into from
Mar 21, 2019
Merged

Conversation

Legioth
Copy link
Member

@Legioth Legioth commented Mar 15, 2019

Related to #1724


This change is Reviewable

Copy link
Contributor

@caalador caalador left a 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.

Copy link
Member Author

@Legioth Legioth left a 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 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.

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.

Copy link
Contributor

@caalador caalador left a 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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

INFO Do not forget to remove this deprecated code someday. rule

* @author Vaadin Ltd
*/
@SuppressWarnings("deprecation")
public interface PendingJavaScriptResult extends ExecutionCanceler {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MINOR Remove this use of "ExecutionCanceler"; it is deprecated. rule

@vaadin-bot
Copy link
Collaborator

SonarQube analysis reported 20 issues

  • MAJOR 5 major
  • MINOR 1 minor
  • INFO 14 info

Watch the comments in this conversation to review them.

Top 10 extra issues

Note: 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:

  1. MAJOR Page.java#L74: Call "Optional#isPresent()" before accessing the value. rule
  2. MAJOR Page.java#L88: Call "Optional#isPresent()" before accessing the value. rule
  3. MAJOR Page.java#L406: Define and throw a dedicated exception instead of using a generic one. rule
  4. MAJOR Element.java#L1458: Make this anonymous inner class a lambda rule
  5. MAJOR Element.java#L1491: Make this anonymous inner class a lambda rule
  6. INFO UIInternals.java#L241: com.vaadin.flow.component.internal.UIInternals.getLastProcessedMessageHash() may expose internal representation by returning UIInternals.lastProcessedMessageHash rule
  7. INFO UIInternals.java#L258: com.vaadin.flow.component.internal.UIInternals.setLastProcessedClientToServerId(int, byte[]) may expose internal representation by storing an externally mutable object into UIInternals.lastProcessedMessageHash rule
  8. INFO Element.java#L130: Do not forget to remove this deprecated code someday. rule
  9. INFO Element.java#L553: Do not forget to remove this deprecated code someday. rule
  10. INFO Element.java#L1166: Do not forget to remove this deprecated code someday. rule

Copy link
Contributor

@caalador caalador left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

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)

Copy link
Contributor

@caalador caalador left a 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: :shipit: complete! all discussions resolved, 1 of 1 LGTMs obtained

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants