Skip to content

Commit

Permalink
re-org rendered HTML in wurbo.js
Browse files Browse the repository at this point in the history
  • Loading branch information
DougAnderson444 committed Jul 16, 2024
1 parent 4053154 commit c5b9075
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/lib/components/WurboComponent.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@
export let templates = null;
/**
* The data that is passed to the component
* The data that is passed to the wasm component. Needs to match the WIT, ie.
* data = {
* tag: 'all-content',
* val: valuesHere
* }
* @type {Object} - Default: null
*/
export let data = {};
export let data = {
tag: 'all-content',
val: null
};
/**
* The wasm URL where the WIT Component can be resolved
* @type {string} - Default: ''
Expand Down Expand Up @@ -79,22 +86,20 @@
// load the import handles into the Wasm component and get the ES module returned
wurbo = new Wurbo({ arrayBuffer: wasmBytes, importables, templates, inline }, eventHandler);
renderedHTML = await wurbo.render({
// technically `all-content` could be named anything, but convention for now is to use `all-content`
tag: 'all-content',
val: data
});
});
// Once the HTML is rendered and the module is loaded, we can activate the event emitters
$: if (data && wurbo)
wurbo.render(data).then(async (html) => {
console.log('data val', data);
renderedHTML = html;
});
// Activate the event listeners
$: if (renderedHTML && wurbo)
(async () => {
// wait for the DOM to reflect the updates first
await tick();
// once the DOM has our elements loaded, we can activate the event emitters
tick().then(() => {
wurbo.activate();
})();
});
</script>

<div>
Expand Down

0 comments on commit c5b9075

Please sign in to comment.