You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit d894ede
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: articles/flow/component-internals/element-api/calling-javascript.adoc
+2-3Lines changed: 2 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,7 +21,7 @@ The other methods described on this page -- [methodname]`executeJs(String, Objec
21
21
[role="since:com.vaadin:vaadin@V25.4"]
22
22
== Declaring JavaScript in Java
23
23
24
-
An interface annotated with [annotationname]`@JsDefinition` declares JavaScript that the build collects into the bundle. It also extends one of the marker interfaces, which decides what its methods declare: [interfacename]`JsInvokers`, covered in this section, for JavaScript that runs on an element when a method is called; [since:com.vaadin:vaadin@V25.5]#[interfacename]`JsModuleInvokers` for JavaScript that runs on what a JavaScript module exports, called through [methodname]`Page.executeModuleJs(Class)`;# or [interfacename]`JsSnippets` for JavaScript that's only passed on as a function (see <<#declaring-snippets,Declaring Snippets>>). An interface extends only one of them.
24
+
An interface annotated with [annotationname]`@JsDefinition` declares JavaScript that the build collects into the bundle. It also extends one of three marker interfaces, which decides what its methods declare: [interfacename]`JsInvokers`, covered in this section, for JavaScript that runs on an element when a method is called; [interfacename]`JsModuleInvokers` for JavaScript that runs on what a JavaScript module exports, called through [methodname]`Page.executeModuleJs(Class)`; or [interfacename]`JsSnippets` for JavaScript that's only passed on as a function (see <<#declaring-snippets,Declaring Snippets>>). An interface extends only one of them.
25
25
26
26
Call the declared JavaScript of a [interfacename]`JsInvokers` interface through [methodname]`Element.executeJs(Class)`, which hands out an implementation of the interface; calling a method of it schedules the JavaScript that the method declares.
27
27
@@ -135,7 +135,6 @@ The interface is checked when [methodname]`executeJs(Class)` hands out the imple
135
135
When the JavaScript isn't about a particular element, declare it the same way and run it through [methodname]`Page.executeJs(Class)`, which works with global browser APIs instead of with an element (see <</flow/advanced/browser-access#declaring-javascript-in-java,Accessing the Browser Page>>). There, every method needs [annotationname]`@JsExpression`, since there's no element whose JavaScript function could be called.
136
136
137
137
[[importing-module-exports]]
138
-
[role="since:com.vaadin:vaadin@V25.5"]
139
138
=== Importing Module Exports
140
139
141
140
[annotationname]`@JsDefinitionImport` imports names from a JavaScript module, so the expressions of a definition can call what the module exports. The module doesn't need to put anything on `window`:
@@ -201,7 +200,7 @@ An interface annotated with [annotationname]`@JsDefinition` that extends [interf
201
200
202
201
A snippet isn't bound to an element, so get the implementation of its interface from [methodname]`JsSnippets.of(Class)` rather than from [methodname]`executeJs(Class)`. The implementation holds no state, so it can be kept in a constant and shared.
203
202
204
-
An interface extends exactly one of [interfacename]`JsInvokers`, [since:com.vaadin:vaadin@V25.5]#[interfacename]`JsModuleInvokers`,# and [interfacename]`JsSnippets`. Passing a [interfacename]`JsSnippets` interface to [methodname]`executeJs(Class)`, or a [interfacename]`JsInvokers` interface to [methodname]`JsSnippets.of()`, is a compile error, since each method accepts only the matching marker type. A method whose return type doesn't match the kind the interface declares is refused with the method named.
203
+
An interface extends exactly one of [interfacename]`JsInvokers`, [interfacename]`JsModuleInvokers`, and [interfacename]`JsSnippets`. Passing a [interfacename]`JsSnippets` interface to [methodname]`executeJs(Class)`, or a [interfacename]`JsInvokers` interface to [methodname]`JsSnippets.of()`, is a compile error, since each method accepts only the matching marker type. A method whose return type doesn't match the kind the interface declares is refused with the method named.
205
204
206
205
The arguments of the Java call are captured and available in the expression as `$0`, `$1`, and so on. The expression is the body of the function, so it has to `return` a value if the caller expects one. The function takes no parameters of its own, unless the method is annotated with [annotationname]`@JsFunctionParameterNames`, which names the parameters that the caller passes to the function when it calls it.
0 commit comments