From 91d9b6992ac0ebee13704a3faefa8fd41a00075e Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 26 Oct 2026 09:23:55 +0100 Subject: zilch: dynamic element creation --- src/zilch/component.template.js | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src/zilch/component.template.js') diff --git a/src/zilch/component.template.js b/src/zilch/component.template.js index e8cb914..6addef2 100644 --- a/src/zilch/component.template.js +++ b/src/zilch/component.template.js @@ -8,14 +8,12 @@ customElements.define("{s}-{s}", class extends HTMLElement {{ this[ZsPtr] = null; }} connectedCallback() {{ - wasm_ready.then(() => {{ - const id = ObjectStore.generateFreeId(); - ObjectStore.registerObject(id, this); - this[ZsPtr] = wasm.exports['export::{s}::init'](id); - }}); + if (this[ZsPtr] === null) {{ + wasm_ready.then(() => {{ + const id = ObjectStore.generateFreeId(); + ObjectStore.registerObject(id, this); + this[ZsPtr] = wasm.exports['export::{s}::init'](id, this[ZsPtr]); + }}); + }} }} - disconnectedCallback() {{ - wasm.exports['export::{s}::deinit'](this[ZsId]); - ObjectStore.free(this); - }} -}}) +}}); -- cgit v1.2.3-70-g09d2