diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-09 14:29:18 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-09 14:32:23 +0200 |
| commit | 812f547d84b5ce1a2924ae16f6257e4fd19efcc0 (patch) | |
| tree | a7d9a931de0e93a23b1613425aa2db3c67980700 /src/zeroscript/component.template.js | |
| parent | 32a251aa9645de070727a6ec91490d3e9219ec7c (diff) | |
zeroscript: make component constructor and destructor optional
Diffstat (limited to 'src/zeroscript/component.template.js')
| -rw-r--r-- | src/zeroscript/component.template.js | 21 |
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); + }} +}}) |