aboutsummaryrefslogtreecommitdiff
path: root/src/zeroscript/component.template.js
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-09 14:29:18 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-09 14:32:23 +0200
commit812f547d84b5ce1a2924ae16f6257e4fd19efcc0 (patch)
treea7d9a931de0e93a23b1613425aa2db3c67980700 /src/zeroscript/component.template.js
parent32a251aa9645de070727a6ec91490d3e9219ec7c (diff)
zeroscript: make component constructor and destructor optional
Diffstat (limited to 'src/zeroscript/component.template.js')
-rw-r--r--src/zeroscript/component.template.js21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zeroscript/component.template.js b/src/zeroscript/component.template.js
new file mode 100644
index 0000000..e8cb914
--- /dev/null
+++ b/src/zeroscript/component.template.js
@@ -0,0 +1,21 @@
+customElements.define("{s}-{s}", class extends HTMLElement {{
+ constructor() {{
+ super();
+ this.attachShadow({{ mode: 'open' }});
+ const template = document.getElementById("@{s}");
+ const node = document.importNode(template.content, true);
+ this.shadowRoot.appendChild(node);
+ this[ZsPtr] = null;
+ }}
+ connectedCallback() {{
+ wasm_ready.then(() => {{
+ const id = ObjectStore.generateFreeId();
+ ObjectStore.registerObject(id, this);
+ this[ZsPtr] = wasm.exports['export::{s}::init'](id);
+ }});
+ }}
+ disconnectedCallback() {{
+ wasm.exports['export::{s}::deinit'](this[ZsId]);
+ ObjectStore.free(this);
+ }}
+}})