-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrender.java
43 lines (36 loc) · 1.31 KB
/
render.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import com.google.gson.Gson;
import org.extism.sdk.manifest.Manifest;
import org.extism.sdk.wasm.UrlWasmSource;
import org.extism.sdk.Plugin;
public class ReactableJava {
static class Template {
private String name;
private String code;
}
static class Invocation {
private String name;
private Map<String, String> props;
}
public static void main(String[] args) {
var url = "https://github.com/dylibso/reactables/releases/latest/download/reactable.core.wasm";
var manifest = new Manifest(List.of(UrlWasmSource.fromUrl(url)));
var reactable = new Plugin(manifest, true, null);
Template template = new Template();
template.setName("greeting-template");
template.setCode(
"function App(props) {\n" +
" return <h1>Hello, {props.customerName}!</h1>\n" +
"}");
Gson gson = new Gson();
String templString = gson.toJson(template);
reactable.call("compileTemplate", templString);
Invocation invocation = new Invocation();
invocation.setName("greeting-template");
Map<String, String> props = new HashMap<>();
props.put("customerName", "Benjamin");
invocation.setProps(props);
String invocationString = gson.toJson(invocation);
String result = reactable.call("render", invocationString);
System.out.println(result);
}
}