In this How-To we will create a simple TypeScript function and call it from the UI.
In a nutshell: create a new screen with a button which displays an info message on click.
Steps:
- Create a new screen
- Add at least one button to this screen.
- Go to the Gitpod environment and create a new file
helloworld.ts
in the directorysrc/webui/akioma/ts
- Add the following code to your newly created file
- Go to the file
index.ts
- Add an import line before the existing export line, which imports your function:
- Add your function also to the export line (in the curly brackets)
Best way to do it: Create a new form, include the button there and add the form to the screen.
You have to enable the button and add a label. For example: “Tell me something”.
export function HelloWorld () {
akioma.swat.Message.informationMessage(`Hello Builder, you're awesome. Keep building!`);
}
import { HelloWorld } from './helloworld';
export default { HelloWorld };
5. Now you have to add the function to an event in the frontend. For that use the attribute eventClick
of the button. There you should add the following: $ [YOUR NAMESPACE HERE].HelloWorld ()
To check what’s the value for [YOUR NAMESPACE HERE] go to src/webui/webpack.config.babel.js
and find the following code snippet
return [
{ // TS build
name: 'typescript-build',
mode: constants.mode[mode],
entry: './clientlogic/index.ts',
output: {
filename: 'app.ts.bundle.js',
path: outputPath,
library: 'app',
libraryTarget: 'assign-properties',
libraryExport: 'default'
},
]
The value of library
defines the namespace, so in this case its app
and in this example the value of the eventClick
attribute would be $ app.HelloWorld ()
Hint: It’s possible that you need to refresh the application without cache or trim the application (which can be done by
build-one trim
) so that your changes are visible