aboutsummaryrefslogtreecommitdiff
path: root/src/zilch/App/main.js
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-12 09:43:19 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-12 09:43:19 +0200
commit0b2af471b6d5dfc4eaf53639102c1b854bbb324b (patch)
treeaba3943b8c54d26d8552d0685d4178bc995d91c3 /src/zilch/App/main.js
parent812f547d84b5ce1a2924ae16f6257e4fd19efcc0 (diff)
first version of zilch
Diffstat (limited to 'src/zilch/App/main.js')
-rw-r--r--src/zilch/App/main.js43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/zilch/App/main.js b/src/zilch/App/main.js
new file mode 100644
index 0000000..265c886
--- /dev/null
+++ b/src/zilch/App/main.js
@@ -0,0 +1,43 @@
+const imports = {
+ object_store: {
+ process: ObjectStore.processWasm,
+ },
+ console: {
+ log(buffer, length) {
+ console.log(ObjectStore.decodeString(buffer, length))
+ },
+ warn(buffer, length) {
+ console.warn(ObjectStore.decodeString(buffer, length))
+ },
+ err(buffer, length) {
+ console.error(ObjectStore.decodeString(buffer, length))
+ },
+ debug(buffer, length) {
+ console.debug(ObjectStore.decodeString(buffer, length))
+ },
+ }
+}
+
+async function wasm_handle_event(target, name, event, pass_event) {
+ await wasm_ready;
+
+ const component = target.getRootNode().host;
+
+ if (pass_event) {
+ const id = ObjectStore.generateFreeId();
+ ObjectStore.registerObject(id, event);
+ wasm.exports[name](component[ZsPtr], id);
+ ObjectStore.free(event);
+ } else {
+ wasm.exports[name](component[ZsPtr]);
+ }
+}
+
+const wasm_ready = WebAssembly.instantiateStreaming(fetch("index.wasm"), imports).then(
+ ({ instance, module }) => {
+ wasm = {
+ exports: instance.exports,
+ memory: instance.exports.memory,
+ }
+ },
+);