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

View File

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

View File

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

View File

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

View File

@ -4,7 +4,7 @@ const services = {};
serviceNames.forEach(path => { serviceNames.forEach(path => {
const name = path.split('/').pop().replace('.ts', ''); // Extract just the file name from the path without .ts 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', id: 'authsig',
componentName: 'HelloEarth', componentName: 'HelloEarth',
slot: 'hello', slot: 'hello'
services: ['messages']
}, },
// { // {
// id: 'wallet1', // id: 'wallet1',