Last active
February 11, 2024 02:39
-
-
Save philholden/4c4c6390dd832c916c9624f48cc193f8 to your computer and use it in GitHub Desktop.
Automerge WASM in Cloudflare Worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import wasmBytes from "./automerge_wasm_bg.wasm"; | |
import * as bg from "./automerge_wasm_bg.js"; | |
const {create} = bg; | |
export interface Env {} | |
export default { | |
async fetch(request, env, ctx): Promise<Response> { | |
// async init cannot happen outside request | |
// see later for generating bg.imports | |
const module = await WebAssembly.instantiate(bg.wasmBytes,bg.imports); | |
bg.__wbg_set_wasm(module.exports); | |
let doc = create(); | |
doc.put("/", "prop1", 100); | |
let x = doc.materialize("_root"); | |
return new Response(JSON.stringify(x)); | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the end
./automerge_wasm_bg.js
looked like this: