启动事件
Trunk 的初始化代码片段将在 WebAssembly 应用程序加载并启动后发出一个事件。
定义
该事件名为 TrunkApplicationStarted
,并在 WebAssembly 加载和初始化后执行。
该事件将具有自定义详情
{
wasm // The web assembly instance
}
示例
以下代码片段可用于在 WebAssembly 应用程序初始化后运行代码
<script type="module">
addEventListener("TrunkApplicationStarted", (event) => {
console.log("application started - bindings:", window.wasmBindings, "WASM:", event.detail.wasm);
// wasm_ffi is a function exported from WASM to JavaScript
window.wasmBindings.wasm_ffi();
// You can also run this via the WASM instance in the details
// event.detail.wasm.wasm_ffi();
});
</script>
另请参阅 vanilla 示例:https://github.com/trunk-rs/trunk/tree/main/examples/vanilla。