-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrender.cs
54 lines (45 loc) · 1.5 KB
/
render.cs
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
44
45
46
47
48
49
50
51
52
53
using System;
using Extism.Sdk;
using System.Text.Json;
namespace SerializeBasic
{
public class Template
{
public string Name { get; set; }
public string Code { get; set; }
}
public class Invocation
{
public string Name { get; set; }
public Dictionary<string, string> Props { get; set; }
}
public class Program
{
public static void Main()
{
var manifest = new Manifest(new UrlWasmSource("https://github.com/dylibso/reactables/releases/latest/download/reactable.core.wasm"));
using var reactable = new Plugin(manifest, new HostFunction[] { }, withWasi: true);
var template = new Template
{
Name = "greeting-template",
Code = @"
function App(props) {
return <h1>Hello, {props.customerName}!</h1>
}
"
};
string templString = JsonSerializer.Serialize(template);
reactable.Call("compileTemplate", templString);
var invocation = new Invocation
{
Name = "greeting-template",
Props = new Dictionary<string, string>() {
{ "customerName", "Benjamin" }
}
};
string invocationString = JsonSerializer.Serialize(invocation);
var result = reactable.Call("render", invocationString);
Console.WriteLine(result);
}
}
}