Class JsDefinitionProxy

java.lang.Object
com.vaadin.flow.js.JsDefinitionProxy

public final class JsDefinitionProxy extends Object
Hands out implementations of JsDefinition interfaces, which turn a call of a declared method into a JsCall and give it to whoever runs it.

The interface is checked here rather than when a method is called, so one that can not work says so when the implementation is handed out.

For internal use only. Call Element.executeJs(Class), which runs the call on the element the implementation was obtained from, or JsSnippets.of(Class) for an interface that declares snippets.

Since:
25.4
  • Method Details

    • create

      public static <T> T create(Class<T> definitionType, SerializableFunction<JsCall,PendingJavaScriptResult> runner)
      Creates an implementation of the given JavaScript definition, which hands every call of it to the given function and answers with what the function answers, for a method that declares a result.
      Type Parameters:
      T - the JavaScript definition type
      Parameters:
      definitionType - the JavaScript definition, not null
      runner - what runs a call of the interface, not null
      Returns:
      an implementation of the interface, not null
      Throws:
      IllegalArgumentException - if the type is not an interface, is not annotated with JsDefinition, or has a method that can not be answered
    • createSnippets

      public static <T> T createSnippets(Class<T> definitionType)
      Creates an implementation of the given JavaScript definition whose methods declare snippets, which answers every call of it with the snippet that the call declares rather than running anything.
      Type Parameters:
      T - the JavaScript definition type
      Parameters:
      definitionType - the JavaScript definition, not null
      Returns:
      an implementation of the interface, not null
      Throws:
      IllegalArgumentException - if the type is not an interface, is not annotated with JsDefinition, or has a method that does not declare a snippet
    • checkDefinition

      public static JsDefinitionProxy.Kind checkDefinition(Class<?> definitionType)
      Checks that the given type is a JavaScript definition that can work, and tells what it declares. The same rules apply to the build, which generates the JavaScript of a definition only when it passes, and to the implementations handed out at runtime.

      Not cached, so that the build, which checks every definition once, holds no reference to the classes of the project it builds.

      For internal use only. May be renamed or removed in a future release.

      Parameters:
      definitionType - the type to check, not null
      Returns:
      what the definition declares, not null
      Throws:
      IllegalArgumentException - if the type is not an interface, is not annotated with JsDefinition, is annotated with JsCalledWith, or has a method that does not fit what the definition declares