added basic composite pattern to load the ui dynamically via json

This commit is contained in:
Samuel Andert
2023-07-22 09:12:03 +02:00
parent 081d052443
commit 01c742e6ce
5 changed files with 145 additions and 28 deletions

View File

@ -0,0 +1,30 @@
<script lang="ts">
import components from '$lib/components.ts';
export let componentsData = [];
export let name = '';
async function getComponent(componentName) {
if (components[componentName]) return components[componentName];
if (componentName === 'Composite') {
const module = await import('$lib/components/Composite.svelte');
return module.default;
}
return null;
}
</script>
{#each componentsData as component (component.id)}
{#await getComponent(component.componentName) then Component}
{#if Component}
<svelte:component
this={Component}
name={component.name}
componentsData={component.components}
/>
{:else}
<p>Component {component.componentName} not found.</p>
{/if}
{/await}
{/each}
<p>Composite: {name}</p>