From 38ec75d19b5dcee481375c440d753aec844206f6 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Tue, 25 Jul 2023 15:31:35 +0200 Subject: [PATCH] feat(composite): enhance service loading for multiple exports --- src/lib/components/Composite.svelte | 7 +++---- src/lib/components/GoogleAuth.svelte | 1 + src/lib/components/HelloEarth/HelloEarth.svelte | 3 --- src/lib/services/provider/setupLitProvider.ts | 4 ++++ src/lib/servicesLoader.ts | 4 ++-- src/routes/+page.svelte | 3 +-- 6 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lib/components/Composite.svelte b/src/lib/components/Composite.svelte index c6d9501..fa72ec9 100644 --- a/src/lib/components/Composite.svelte +++ b/src/lib/components/Composite.svelte @@ -72,7 +72,6 @@ } return null; } - async function getServiceProps(component) { const loadedServices = []; if (component.services) { @@ -89,15 +88,15 @@
{#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}
{ - acc[component.services[idx]] = currFn; + {...serviceProps.reduce((acc, currServiceModule, idx) => { + acc[component.services[idx]] = currServiceModule; return acc; }, {})} /> diff --git a/src/lib/components/GoogleAuth.svelte b/src/lib/components/GoogleAuth.svelte index 726e0a6..e74aa0a 100644 --- a/src/lib/components/GoogleAuth.svelte +++ b/src/lib/components/GoogleAuth.svelte @@ -31,6 +31,7 @@ onMount(async () => { try { provider = await setupLitProvider.setupLitProvider(); + setupLitProvider.alertMe(); logMessage('Component mounted.'); diff --git a/src/lib/components/HelloEarth/HelloEarth.svelte b/src/lib/components/HelloEarth/HelloEarth.svelte index 502b71e..1c9a1a6 100644 --- a/src/lib/components/HelloEarth/HelloEarth.svelte +++ b/src/lib/components/HelloEarth/HelloEarth.svelte @@ -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'); }); diff --git a/src/lib/services/provider/setupLitProvider.ts b/src/lib/services/provider/setupLitProvider.ts index 5b8e537..50e10dc 100644 --- a/src/lib/services/provider/setupLitProvider.ts +++ b/src/lib/services/provider/setupLitProvider.ts @@ -28,3 +28,7 @@ export async function setupLitProvider() { return provider; } + +export function alertMe() { + alert("hello") +} \ No newline at end of file diff --git a/src/lib/servicesLoader.ts b/src/lib/servicesLoader.ts index 64cb6f0..b7c7818 100644 --- a/src/lib/servicesLoader.ts +++ b/src/lib/servicesLoader.ts @@ -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; \ No newline at end of file +export default services; diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 3da1e24..947f0a4 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -13,8 +13,7 @@ { id: 'authsig', componentName: 'HelloEarth', - slot: 'hello', - services: ['messages'] + slot: 'hello' }, // { // id: 'wallet1',