Record Class JsCall

java.lang.Object
java.lang.Record
com.vaadin.flow.js.JsCall
Record Components:
definitionType - the JavaScript definition the call was made on
methodName - the name of the called method
arguments - the arguments of the call, in declaration order, any of which may be null
All Implemented Interfaces:
Serializable

public record JsCall(Class<?> definitionType, String methodName, List<Object> arguments) extends Record implements Serializable
A call made through Element.executeJs(Class): which definition interface, which method of it, and the arguments that were passed.

The call is what is scheduled, and what a driver of the client side that can not run JavaScript sees in the pending invocation queue. A browser is sent less than this: the identifier of the function to run and the arguments, never the JavaScript itself, which it looks up in the bundle, and never the interface or the method, which stay on the server. Such a driver can dispatch on the interface and the method, or hand the call to an implementation of the same interface with invokeOn(Object) and let Java dispatch it:

 if (call.definitionType() == FocusJs.class) {
     call.invokeOn(new FocusSimulation(Element.get(pending.getOwner())));
 }
 
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    JsCall(Class<?> definitionType, String methodName, List<Object> arguments)
    Creates a call of the given method of the given JavaScript definition.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the arguments record component.
    Returns the value of the definitionType record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    static String
    functionId(String expression, int argumentCount)
    Gets the identifier of the function that runs the given JavaScript with the given number of arguments, which is the key the generated bundle registers that function under and the only thing the client is told about a call.
    Gets the JavaScript that this call runs in a browser, as declared by JsExpression on the called method.
    final int
    Returns a hash code value for this object.
    invokeOn(Object implementation)
    Runs this call on an implementation of the JavaScript definition, which is how a driver of the client side reproduces it without running the JavaScript.
    Returns the value of the methodName record component.
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JsCall

      public JsCall(Class<?> definitionType, String methodName, List<Object> arguments)
      Creates a call of the given method of the given JavaScript definition.
      Parameters:
      definitionType - the JavaScript definition, not null
      methodName - the name of the called method, not null
      arguments - the arguments of the call, not null
  • Method Details

    • functionId

      public static String functionId(String expression, int argumentCount)
      Gets the identifier of the function that runs the given JavaScript with the given number of arguments, which is the key the generated bundle registers that function under and the only thing the client is told about a call.

      A hash of the JavaScript, so that the name of the Java that declared it stays on the server. The number of arguments is hashed with it, since it is what the parameters of the generated function are made of, and two methods that declare the same JavaScript for a different number of arguments are two functions.

      Parameters:
      expression - the declared JavaScript, not null
      argumentCount - the number of arguments
      Returns:
      the function identifier, not null
    • getExpression

      public String getExpression()
      Gets the JavaScript that this call runs in a browser, as declared by JsExpression on the called method.

      The expression is not sent to the client, which runs the function that the build generated from the same declaration. It is available here for the server side, for instance for a test that asserts what a browser would run.

      Returns:
      the JavaScript expression, not null
    • invokeOn

      public Object invokeOn(Object implementation)
      Runs this call on an implementation of the JavaScript definition, which is how a driver of the client side reproduces it without running the JavaScript.
      Parameters:
      implementation - an implementation of definitionType(), not null
      Returns:
      the value returned by the implementation, or null for a void method
      Throws:
      IllegalArgumentException - if the implementation does not implement definitionType()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • definitionType

      public Class<?> definitionType()
      Returns the value of the definitionType record component.
      Returns:
      the value of the definitionType record component
    • methodName

      public String methodName()
      Returns the value of the methodName record component.
      Returns:
      the value of the methodName record component
    • arguments

      public List<Object> arguments()
      Returns the value of the arguments record component.
      Returns:
      the value of the arguments record component