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.
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 TypeMethodDescriptionfindMissingFromGeneratedFile(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
-
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.
-