Interface JsInvokers

All Superinterfaces:
Serializable
All Known Subinterfaces:
AbstractNodeStateProvider.AttachExistingElementJs, AbstractRouteNotFoundError.CopilotJs, Element.CallFunctionJs, Element.ElementJs, Element.ScrollIntoViewJs, ElementJsInitializerRegistration.InitializerJs, ExtendedClientDetails.ClientDetailsJs, Focusable.FocusJs, History.HistoryJs, Page.NavigationJs, Page.PageJs, PublishedServerEventHandlerRpcHandler.PromiseJs, ScreenOrientation.ScreenOrientationJs, ShortcutRegistration.ShortcutJs, SignalInput.MirrorJs, UI.UiJs, UidlRequestHandler.MprPushStateJs, UIInternals.TitleJs, WakeLock.WakeLockJs, WebComponent.CustomEventJs, WebComponentBootstrapHandler.StylesheetJs, WebComponentUI.ThemeAttributesJs, WebPushJs, WebStorage.WebStorageJs

public interface JsInvokers extends Serializable
Marks an interface whose methods declare, with JsExpression, the JavaScript they run when they are called. An implementation is obtained from Element.executeJs(Class) or Page.executeJs(Class), and calling a method of it schedules the declared JavaScript to run on the client.

The interface is also annotated with JsDefinition, which is what makes it findable during the build: its JavaScript is collected into the generated bundle, so the client never has to build a function from a string. That is what keeps a server-initiated call compatible with a content security policy that does not allow unsafe-eval. See JsDefinition for how a definition that extends another interface is declared.

An interface whose methods only answer with snippets extends JsSnippets instead. An interface can not extend both. Both are Serializable, so an implementation can be kept in a field of a component.

 @JsDefinition
 public interface ScrollJs extends JsInvokers {

     @JsExpression("this.scrollTop = $0;")
     void scrollTo(int top);
 }

 element.executeJs(ScrollJs.class).scrollTo(100);
 
See Also: