Updated Composite to render a FallBack Component, when no visual component has been rendered.
This commit is contained in:
parent
7f57036e94
commit
e4cb7df353
@ -16,7 +16,7 @@
|
|||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
id: 'child',
|
id: 'child',
|
||||||
component: 'LearnReady',
|
// component: 'LearnReady',
|
||||||
slot: 'left',
|
slot: 'left',
|
||||||
store: {
|
store: {
|
||||||
xstate: 'NOTREADY'
|
xstate: 'NOTREADY'
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onDestroy } from 'svelte';
|
import { onDestroy } from 'svelte';
|
||||||
import Composite from './Composite.svelte';
|
import Composite from './Composite.svelte';
|
||||||
|
import FallBack from './FallBack.svelte';
|
||||||
import components from '$lib/core/componentLoader';
|
import components from '$lib/core/componentLoader';
|
||||||
import services from '$lib/core/servicesLoader';
|
import services from '$lib/core/servicesLoader';
|
||||||
import { dataStore } from '$lib/core/dataLoader';
|
import { dataStore } from '$lib/core/dataLoader';
|
||||||
@ -19,7 +20,7 @@
|
|||||||
layout?: ICompositeLayout;
|
layout?: ICompositeLayout;
|
||||||
id: string;
|
id: string;
|
||||||
slot?: string;
|
slot?: string;
|
||||||
component: string;
|
component?: string;
|
||||||
services?: string[];
|
services?: string[];
|
||||||
map?: Record<string, string>;
|
map?: Record<string, string>;
|
||||||
store?: Record<string, any>;
|
store?: Record<string, any>;
|
||||||
@ -157,7 +158,7 @@
|
|||||||
const module = await components[componentName]();
|
const module = await components[componentName]();
|
||||||
return module.default;
|
return module.default;
|
||||||
}
|
}
|
||||||
return null;
|
return FallBack;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadService(serviceName: string) {
|
async function loadService(serviceName: string) {
|
||||||
@ -169,7 +170,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loadComponentAndService(component: IComposite) {
|
async function loadComponentAndService(component: IComposite) {
|
||||||
return await getComponent(component.component);
|
const componentName = component.component || 'FallBack';
|
||||||
|
return await getComponent(componentName);
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@ -179,17 +181,14 @@
|
|||||||
>
|
>
|
||||||
{#if composite?.servicesLoaded}
|
{#if composite?.servicesLoaded}
|
||||||
{#await loadComponentAndService(composite) then Component}
|
{#await loadComponentAndService(composite) then Component}
|
||||||
{#if Component}
|
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={Component}
|
this={Component}
|
||||||
id={composite.id}
|
id={composite.id}
|
||||||
store={getCompositeStore(composite.id)}
|
store={getCompositeStore(composite.id)}
|
||||||
services={loadedServices}
|
services={loadedServices}
|
||||||
/>
|
/>
|
||||||
{/if}
|
|
||||||
{/await}
|
{/await}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if composite?.children}
|
{#if composite?.children}
|
||||||
{#each composite.children as child (child.id)}
|
{#each composite.children as child (child.id)}
|
||||||
<div
|
<div
|
||||||
@ -198,7 +197,6 @@
|
|||||||
>
|
>
|
||||||
{#if child.servicesLoaded}
|
{#if child.servicesLoaded}
|
||||||
{#await loadComponentAndService(child) then ChildComponent}
|
{#await loadComponentAndService(child) then ChildComponent}
|
||||||
{#if ChildComponent}
|
|
||||||
<svelte:component
|
<svelte:component
|
||||||
this={ChildComponent}
|
this={ChildComponent}
|
||||||
id={child.id}
|
id={child.id}
|
||||||
@ -208,12 +206,7 @@
|
|||||||
{#if child.children && child.children.length}
|
{#if child.children && child.children.length}
|
||||||
<Composite composite={child} />
|
<Composite composite={child} />
|
||||||
{/if}
|
{/if}
|
||||||
{:else}
|
|
||||||
<p>Component {child.component} not found.</p>
|
|
||||||
{/if}
|
|
||||||
{/await}
|
{/await}
|
||||||
{:else}
|
|
||||||
<p>Loading services for child {child.id}...</p>
|
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/each}
|
{/each}
|
||||||
|
4
src/lib/core/FallBack.svelte
Normal file
4
src/lib/core/FallBack.svelte
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
<script>
|
||||||
|
export let id;
|
||||||
|
console.log(`FallBack component rendered with id ${id}`);
|
||||||
|
</script>
|
Loading…
x
Reference in New Issue
Block a user