Record Class JsCall
- Record Components:
definitionType- the JavaScript definition the call was made onmethodName- the name of the called methodarguments- the arguments of the call, in declaration order, any of which may benull
- All Implemented Interfaces:
Serializable
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())));
}
- Since:
- 25.4
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the value of theargumentsrecord component.Class<?> Returns the value of thedefinitionTyperecord component.final booleanIndicates whether some other object is "equal to" this one.Gets the arguments of this call as the client receives them, which spreads the array that a variadic call collects its trailing arguments into.static StringfunctionId(String expression, int parameterCount, boolean variadic) Gets the identifier of the function that runs the given JavaScript with the given parameters, 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 byJsExpressionon the called method.Gets the identifier of the function that runs this call, which is what the client looks the JavaScript up in the bundle by.final inthashCode()Returns a hash code value for this object.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.booleanWhether the called method collects a variable number of arguments into its last parameter.Returns the value of themethodNamerecord component.Object[]parametersFor(@Nullable Element runOn) Gets what this call is sent with: its arguments as the client receives them, and then the element to run the function on, which the client applies the function to.final StringtoString()Returns a string representation of this record class.
-
Constructor Details
-
JsCall
Creates a call of the given method of the given JavaScript definition.- Parameters:
definitionType- the JavaScript definition, notnullmethodName- the name of the called method, notnullarguments- the arguments of the call, notnull
-
-
Method Details
-
functionId
Gets the identifier of the function that runs the given JavaScript with the given parameters, 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. What the parameters of the generated function are made of is hashed with it, so that two methods declaring the same JavaScript are the same function only when it runs the same way: for the same number of parameters, and with the last one collecting a variable number of arguments in both or in neither.
- Parameters:
expression- the declared JavaScript, notnullparameterCount- the number of parameters of the declaring methodvariadic- whether its last parameter collects a variable number of arguments- Returns:
- the function identifier, not
null
-
getFunctionId
Gets the identifier of the function that runs this call, which is what the client looks the JavaScript up in the bundle by.- Returns:
- the function identifier, not
null
-
isVariadic
public boolean isVariadic()Whether the called method collects a variable number of arguments into its last parameter.The generated function collects them into a rest parameter, which does not count towards the length of the function, so the client is told how many arguments a call of such a function carries rather than reading it off the function.
- Returns:
truewhen the called method is variadic
-
flattenArguments
Gets the arguments of this call as the client receives them, which spreads the array that a variadic call collects its trailing arguments into.arguments()holds what Java passed, where a variadic tail is a single array argument. The browser gets each of its values on its own, so that an element, a return channel or a function among them is sent as the reference it is rather than as part of a nested array.- Returns:
- the arguments as the client receives them, not
null
-
parametersFor
Gets what this call is sent with: its arguments as the client receives them, and then the element to run the function on, which the client applies the function to.The element a call was made on goes into that last place, and a call made on nothing in particular - page JavaScript, which works on globals - puts
nullthere, so a client reads the two the same way.- Parameters:
runOn- the element to run the function on, ornullfor page JavaScript, which runs on nothing in particular- Returns:
- the parameters of the call, not
null
-
getExpression
Gets the JavaScript that this call runs in a browser, as declared byJsExpressionon 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
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 ofdefinitionType(), notnull- Returns:
- the value returned by the implementation, or
nullfor a void method - Throws:
IllegalArgumentException- if the implementation does not implementdefinitionType()
-
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
definitionType
Returns the value of thedefinitionTyperecord component.- Returns:
- the value of the
definitionTyperecord component
-
methodName
Returns the value of themethodNamerecord component.- Returns:
- the value of the
methodNamerecord component
-
arguments
Returns the value of theargumentsrecord component.- Returns:
- the value of the
argumentsrecord component
-