feat(composite): enhance service loading for multiple exports

This commit is contained in:
Samuel Andert 2023-07-25 15:31:35 +02:00
parent c47cf1e338
commit 38ec75d19b
6 changed files with 11 additions and 11 deletions

View File

@ -72,7 +72,6 @@
}
return null;
}
async function getServiceProps(component) {
const loadedServices = [];
if (component.services) {
@ -89,15 +88,15 @@
<div class="grid w-full h-full" style="display: grid; {componentsData.layout || ''}">
{#each componentsData.children as component (component.id)}
{#await Promise.all( [getComponent(component.componentName), getServiceProps(component)] ) then [Component, loadedServices]}
{#await Promise.all( [getComponent(component.componentName), getServiceProps(component)] ) then [Component, serviceProps]}
{#if Component}
<div class="w-full h-full overflow-hidden {component.slot}">
<svelte:component
this={Component}
id={component.id}
{...component.props}
{...loadedServices.reduce((acc, currFn, idx) => {
acc[component.services[idx]] = currFn;
{...serviceProps.reduce((acc, currServiceModule, idx) => {
acc[component.services[idx]] = currServiceModule;
return acc;
}, {})}
/>

View File

@ -31,6 +31,7 @@
onMount(async () => {
try {
provider = await setupLitProvider.setupLitProvider();
setupLitProvider.alertMe();
logMessage('Component mounted.');

View File

@ -7,10 +7,7 @@
const store = getComponentStore(id);
$: console.log('store:', $store);
export let messages;
onMount(async () => {
console.log('messages: ' + JSON.stringify(messages));
console.log('hello Earth');
});
</script>

View File

@ -28,3 +28,7 @@ export async function setupLitProvider() {
return provider;
}
export function alertMe() {
alert("hello")
}

View File

@ -4,7 +4,7 @@ const services = {};
serviceNames.forEach(path => {
const name = path.split('/').pop().replace('.ts', ''); // Extract just the file name from the path without .ts
services[name] = () => import(/* @vite-ignore */ `/src/lib/services/${path}`);
services[name] = () => import(/* @vite-ignore */ `/src/lib/services/${path}`).then(mod => mod);
});
export default services;
export default services;

View File

@ -13,8 +13,7 @@
{
id: 'authsig',
componentName: 'HelloEarth',
slot: 'hello',
services: ['messages']
slot: 'hello'
},
// {
// id: 'wallet1',