Class TaskGenerateJsDefinitions
- All Implemented Interfaces:
FallibleCommand
FrontendUtils.JS_DEFINITIONS_FILE_NAME, which registers the
JavaScript of every JsDefinition interface on the class path as an
ordinary function of the bundle: in one registry for the methods that run
their JavaScript when called, in another for those of them that are annotated
with JsWithExecutionContext and take the execution context as their
first parameter, and in a third for the methods that declare a
JsSnippet, which the client turns into a function when it decodes the
snippet. A definition that does not pass
JsDefinitionProxy.checkDefinition(Class) is left out, with an error
in the log.
The snippet registry also holds the EventData values and the
DomEvent.filter() of the DomEvent classes on the class path
that the client would otherwise compile from a string, see
BundledEventData, so that the server can send the identifier of a
function instead of the value.
This is what lets the client run a server-initiated call without compiling
anything from a string: the server sends the identifier of the function to
run, which is a hash of the JavaScript, and the function is already in the
bundle. The call survives a content security policy that does not allow
unsafe-eval, the JavaScript an application can be made to run is
known when it is built, and what declared it in Java stays there.
Outside production mode the file also registers what a developer wrote for each function, so that a message about a call in the browser names it rather than a hash. A production bundle carries the functions alone.
For internal use only. May be renamed or removed in a future release.
- Since:
- 25.4
-
Method Summary
Modifier and TypeMethodDescriptionThe names of the JavaScript definitions that the generated file names a function of, for a caller that has to find which of them a change of another class affects without scanning for them.findMissingFromGeneratedFile(Options options, Collection<Class<?>> definitions) The JavaScript definitions of the given ones whose JavaScript the generated file does not carry, which is the JavaScript a browser can run of them.protected StringGet file content for writing to the generated file.protected FileGet the generated file where content will be written.protected booleanCheck if it should generate the file or not.updateJsDefinitions(Options options, Collection<Class<?>> definitions) Writes the generated file again so that it carries what the given definitions declare, for a caller that has to update it while the application runs rather than as part of a build.Methods inherited from class com.vaadin.flow.server.frontend.AbstractTaskClientGenerator
executeMethods inherited from class com.vaadin.flow.server.frontend.AbstractFileGeneratorFallibleCommand
setGeneratedFileSupport, track, track, writeIfChanged, writeIfChanged
-
Method Details
-
getFileContent
Description copied from class:AbstractTaskClientGeneratorGet file content for writing to the generated file.- Specified by:
getFileContentin classAbstractTaskClientGenerator- Returns:
- content of the file.
-
findMissingFromGeneratedFile
public static List<Class<?>> findMissingFromGeneratedFile(Options options, Collection<Class<?>> definitions) The JavaScript definitions of the given ones whose JavaScript the generated file does not carry, which is the JavaScript a browser can run of them.- Parameters:
options- where the file is, notnulldefinitions- the JavaScript definitions to look for, notnull- Returns:
- those the file does not carry, empty when it carries all of them
-
findDefinitionNamesInGeneratedFile
The names of the JavaScript definitions that the generated file names a function of, for a caller that has to find which of them a change of another class affects without scanning for them. Only a file written for a development build names what declared its functions.- Parameters:
options- where the file is, notnull- Returns:
- the binary names of the definitions, empty when there is no file or it names nothing
-
updateJsDefinitions
Writes the generated file again so that it carries what the given definitions declare, for a caller that has to update it while the application runs rather than as part of a build.What the file already holds is kept: a function it registers is what a browser that has the file can run, and the caller only knows about the definitions it passes in. A function nothing declares any longer stays in the file with nothing calling it, until a build renders the file again.
Goes through the same write as
AbstractTaskClientGenerator.execute(), which leaves the file alone when its content would not change and writes it atomically otherwise, so a dev server is not told about an update that is not one and never reads a file that is half written.- Parameters:
options- where the file is, notnulldefinitions- the JavaScript definitions to write it for, notnulland not empty- Returns:
- those of them the file does not carry afterwards, empty when it carries all of them
-
getGeneratedFile
Description copied from class:AbstractTaskClientGeneratorGet the generated file where content will be written.- Specified by:
getGeneratedFilein classAbstractTaskClientGenerator- Returns:
- the generated file.
-
shouldGenerate
protected boolean shouldGenerate()Description copied from class:AbstractTaskClientGeneratorCheck if it should generate the file or not.- Specified by:
shouldGeneratein classAbstractTaskClientGenerator- Returns:
- true if it should generate, false otherwise.
-