From 0161f4ba4f408953c88dd3f454de399d539fd14b Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Wed, 26 Jul 2023 09:23:15 +0200 Subject: [PATCH] breaking changes, major refactoring of Composite --- src/lib/components/Composite.svelte | 147 ------------------ src/lib/components/GoogleAuth.svelte | 4 +- .../components/HelloEarth/HelloEarth.svelte | 13 +- src/lib/components/Messages.svelte | 2 +- src/lib/components/SendMessage.svelte | 6 +- src/lib/components/Wallet/Wallet.svelte | 4 +- src/lib/core/Composite.svelte | 144 +++++++++++++++++ src/lib/{ => core}/componentLoader.ts | 0 src/lib/core/compositeStores.ts | 16 ++ src/lib/core/servicesLoader.ts | 16 ++ .../createLitSession/createLitSession.ts | 2 +- src/lib/servicesLoader.ts | 10 -- src/lib/stores/componentStores.ts | 16 -- src/routes/+page.svelte | 47 +++--- 14 files changed, 212 insertions(+), 215 deletions(-) delete mode 100644 src/lib/components/Composite.svelte create mode 100644 src/lib/core/Composite.svelte rename src/lib/{ => core}/componentLoader.ts (100%) create mode 100644 src/lib/core/compositeStores.ts create mode 100644 src/lib/core/servicesLoader.ts delete mode 100644 src/lib/servicesLoader.ts delete mode 100644 src/lib/stores/componentStores.ts diff --git a/src/lib/components/Composite.svelte b/src/lib/components/Composite.svelte deleted file mode 100644 index c475645..0000000 --- a/src/lib/components/Composite.svelte +++ /dev/null @@ -1,147 +0,0 @@ - - -
- {#each componentsData.children as component (component.id)} -
- {#await Promise.all( [getComponent(component.componentName), getServiceProps(component)] ) then [Component, serviceProps]} - {#if Component} - { - acc[component.services[idx]] = currServiceModule; - return acc; - }, {})} - /> - - {#if component.actions} -
- {#each component.actions as action} - {#await getComponent(action) then ActionComponent} - {#if ActionComponent} - - {:else} -

Action {action} not found.

- {/if} - {/await} - {/each} -
- {/if} - - {#if component.children && component.children.length} - - {/if} - {:else} -

Component {component.componentName} not found.

- {/if} - {/await} -
- {/each} -
diff --git a/src/lib/components/GoogleAuth.svelte b/src/lib/components/GoogleAuth.svelte index ad6215f..a29562f 100644 --- a/src/lib/components/GoogleAuth.svelte +++ b/src/lib/components/GoogleAuth.svelte @@ -8,7 +8,7 @@ const redirectUri = 'http://localhost:5173/'; - export let setupLit; + export let services; let view = 'sign_in'; let sessionSigs; @@ -30,7 +30,7 @@ onMount(async () => { try { - provider = await setupLit.connectProvider(); + provider = await services.setupLit.connectProvider(); logMessage('Component mounted.'); diff --git a/src/lib/components/HelloEarth/HelloEarth.svelte b/src/lib/components/HelloEarth/HelloEarth.svelte index 90fa10d..1fd4ec4 100644 --- a/src/lib/components/HelloEarth/HelloEarth.svelte +++ b/src/lib/components/HelloEarth/HelloEarth.svelte @@ -1,16 +1,19 @@ diff --git a/src/lib/components/Messages.svelte b/src/lib/components/Messages.svelte index f9b7471..fc916c5 100644 --- a/src/lib/components/Messages.svelte +++ b/src/lib/components/Messages.svelte @@ -1,7 +1,7 @@ + +
+ {#if composite && composite.children} + {#each composite.children as child (child.id)} +
+ {#await Promise.all( [getComponent(child.component), getServiceProps(child)] ) then [Component, serviceProps]} + {#if Component} + + {#if child.children && child.children.length} + + {/if} + {:else} +

Component {child.component} not found.

+ {/if} + {/await} +
+ {/each} + {/if} +
diff --git a/src/lib/componentLoader.ts b/src/lib/core/componentLoader.ts similarity index 100% rename from src/lib/componentLoader.ts rename to src/lib/core/componentLoader.ts diff --git a/src/lib/core/compositeStores.ts b/src/lib/core/compositeStores.ts new file mode 100644 index 0000000..7e586c0 --- /dev/null +++ b/src/lib/core/compositeStores.ts @@ -0,0 +1,16 @@ +import { writable } from 'svelte/store'; + +const compositeStores = new Map(); + +// Create or retrieve a composite store +export function createCompositeStore(compositeId: string, initialState = {}) { + if (!compositeStores.has(compositeId)) { + compositeStores.set(compositeId, writable(initialState)); + } + return compositeStores.get(compositeId); +} + +// Get composite store or create a default empty one if not exists +export function getCompositeStore(compositeId: string) { + return compositeStores.get(compositeId) || createCompositeStore(compositeId); +} diff --git a/src/lib/core/servicesLoader.ts b/src/lib/core/servicesLoader.ts new file mode 100644 index 0000000..cf25137 --- /dev/null +++ b/src/lib/core/servicesLoader.ts @@ -0,0 +1,16 @@ +import serviceNames from 'virtual:services-list'; + +const services: { [key: string]: Function } = {}; + +serviceNames.forEach(path => { + const serviceName = path.split('/').pop().replace('.ts', ''); + services[serviceName] = () => import(/* @vite-ignore */ `/src/lib/services/${path}`) + .then(mod => { + console.log(`Loaded service ${serviceName} with the following properties:`, Object.keys(mod)); + if (mod.default) return mod.default; + return mod; + }); +}); + +export default services; + diff --git a/src/lib/services/createLitSession/createLitSession.ts b/src/lib/services/createLitSession/createLitSession.ts index f770e5f..7d97542 100644 --- a/src/lib/services/createLitSession/createLitSession.ts +++ b/src/lib/services/createLitSession/createLitSession.ts @@ -4,7 +4,7 @@ import { LitAccessControlConditionResource, LitAbility } from '@lit-protocol/aut export async function createLitSession( provider: IProvider, pkpPublicKey: string, - authMethod: any + authMethod: any, ): Promise { const litResource = new LitAccessControlConditionResource('*'); return await provider.getSessionSigs({ diff --git a/src/lib/servicesLoader.ts b/src/lib/servicesLoader.ts deleted file mode 100644 index b7c7818..0000000 --- a/src/lib/servicesLoader.ts +++ /dev/null @@ -1,10 +0,0 @@ -import serviceNames from 'virtual:services-list'; - -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}`).then(mod => mod); -}); - -export default services; diff --git a/src/lib/stores/componentStores.ts b/src/lib/stores/componentStores.ts deleted file mode 100644 index 3c3e44d..0000000 --- a/src/lib/stores/componentStores.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { writable } from 'svelte/store'; - -const componentStores = new Map(); - -// Create or retrieve a component store -export function createComponentStore(componentId, initialState = {}) { - if (!componentStores.has(componentId)) { - componentStores.set(componentId, writable(initialState)); - } - return componentStores.get(componentId); -} - -// Get component store or create a default empty one if not exists -export function getComponentStore(componentId) { - return componentStores.get(componentId) || createComponentStore(componentId); -} diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index dad1c34..898ffb1 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,36 +1,24 @@ - +