From b546a22302e678a999a4800814cc02e7444ba1f8 Mon Sep 17 00:00:00 2001 From: Samuel Andert Date: Thu, 27 Jul 2023 14:28:40 +0200 Subject: [PATCH] updated the reference key for data and store to store mapping to @data: and @storeID: in composite. --- src/lib/components/AppBar.svelte | 3 ++- .../components/HelloEarth/HelloEarth.svelte | 1 - src/lib/core/Composite.svelte | 16 +++++++++++---- src/routes/+page.svelte | 2 +- src/routes/helloearth/+page.svelte | 8 +++----- src/routes/messages/+page.svelte | 7 ++----- src/routes/wallet/+page.svelte | 20 ++++++++++++------- 7 files changed, 33 insertions(+), 24 deletions(-) diff --git a/src/lib/components/AppBar.svelte b/src/lib/components/AppBar.svelte index f60a8a8..33781c5 100644 --- a/src/lib/components/AppBar.svelte +++ b/src/lib/components/AppBar.svelte @@ -1,8 +1,9 @@ -

Nova

+
diff --git a/src/lib/components/HelloEarth/HelloEarth.svelte b/src/lib/components/HelloEarth/HelloEarth.svelte index fc2a6d2..86c66a5 100644 --- a/src/lib/components/HelloEarth/HelloEarth.svelte +++ b/src/lib/components/HelloEarth/HelloEarth.svelte @@ -3,7 +3,6 @@ export let store; let isStoreLoaded = false; - $: console.log('store: ' + JSON.stringify($store)); $: if (services && services.helloEarthAlert) { // services.helloEarthAlert.alertMe(); diff --git a/src/lib/core/Composite.svelte b/src/lib/core/Composite.svelte index 6096bd2..13bc11d 100644 --- a/src/lib/core/Composite.svelte +++ b/src/lib/core/Composite.svelte @@ -93,10 +93,13 @@ if (component.map) { const localStore = getCompositeStore(component.id); - for (const [localKey, external] of Object.entries(component.map)) { - const [externalID, externalKey] = external.split('.').map((item) => item.trim()); + for (const [localKey, mapping] of Object.entries(component.map)) { + const isDataMapping = mapping.startsWith('@data:'); + const isStoreMapping = mapping.startsWith('@'); + + if (isDataMapping) { + const externalKey = mapping.replace('@data:', '').trim(); - if (externalID === 'data') { const unsubscribe = dataStore.subscribe((store) => { if (externalKey in store) { if (store[externalKey] && typeof store[externalKey].subscribe === 'function') { @@ -114,7 +117,12 @@ }); unsubscribers.push(unsubscribe); - } else { + } else if (isStoreMapping) { + const [externalID, externalKey] = mapping + .replace('@', '') + .split(':') + .map((item) => item.trim()); + const externalStore = getCompositeStore(externalID); if (externalStore) { const unsubscribe = externalStore.subscribe((externalState) => { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 6b58b9b..6ebb823 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -2,7 +2,7 @@ import Composite from '$lib/core/Composite.svelte'; let composite = { - id: 'google', + id: 'login', component: 'GoogleAuth', services: ['setupLit'] }; diff --git a/src/routes/helloearth/+page.svelte b/src/routes/helloearth/+page.svelte index dab1f6c..6a3eba6 100644 --- a/src/routes/helloearth/+page.svelte +++ b/src/routes/helloearth/+page.svelte @@ -2,7 +2,7 @@ import Composite from '$lib/core/Composite.svelte'; let composite = { - id: 'composite', + id: 'hello', layout: { areas: ` "main" @@ -16,10 +16,8 @@ component: 'HelloEarth', slot: 'main', map: { - pkpWallet: 'w.pkpWallet', - rpcURL: 'w.rpcURL', - messages: 'data.queryMessages', - todos: 'data.queryTodos' + pkpWallet: '@wallet.pkpWallet', + todos: '@data:queryTodos' }, services: ['helloEarthAlert'] }, diff --git a/src/routes/messages/+page.svelte b/src/routes/messages/+page.svelte index 676ed2f..a81a623 100644 --- a/src/routes/messages/+page.svelte +++ b/src/routes/messages/+page.svelte @@ -1,11 +1,8 @@