updated the reference key for data and store to store mapping to @data: and @storeID: in composite.

This commit is contained in:
Samuel Andert 2023-07-27 14:28:40 +02:00
parent 1ce7b80c9b
commit b546a22302
7 changed files with 33 additions and 24 deletions

View File

@ -1,8 +1,9 @@
<script> <script>
import { AppBar } from '@skeletonlabs/skeleton'; import { AppBar } from '@skeletonlabs/skeleton';
export let store;
</script> </script>
<AppBar> <AppBar>
<h1 class="h4">Nova</h1> <!-- <h1 class="h4">{$store.dapp.name}</h1> -->
<!-- <svelte:fragment slot="trail">(actions)</svelte:fragment> --> <!-- <svelte:fragment slot="trail">(actions)</svelte:fragment> -->
</AppBar> </AppBar>

View File

@ -3,7 +3,6 @@
export let store; export let store;
let isStoreLoaded = false; let isStoreLoaded = false;
$: console.log('store: ' + JSON.stringify($store));
$: if (services && services.helloEarthAlert) { $: if (services && services.helloEarthAlert) {
// services.helloEarthAlert.alertMe(); // services.helloEarthAlert.alertMe();

View File

@ -93,10 +93,13 @@
if (component.map) { if (component.map) {
const localStore = getCompositeStore(component.id); const localStore = getCompositeStore(component.id);
for (const [localKey, external] of Object.entries(component.map)) { for (const [localKey, mapping] of Object.entries(component.map)) {
const [externalID, externalKey] = external.split('.').map((item) => item.trim()); 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) => { const unsubscribe = dataStore.subscribe((store) => {
if (externalKey in store) { if (externalKey in store) {
if (store[externalKey] && typeof store[externalKey].subscribe === 'function') { if (store[externalKey] && typeof store[externalKey].subscribe === 'function') {
@ -114,7 +117,12 @@
}); });
unsubscribers.push(unsubscribe); unsubscribers.push(unsubscribe);
} else { } else if (isStoreMapping) {
const [externalID, externalKey] = mapping
.replace('@', '')
.split(':')
.map((item) => item.trim());
const externalStore = getCompositeStore(externalID); const externalStore = getCompositeStore(externalID);
if (externalStore) { if (externalStore) {
const unsubscribe = externalStore.subscribe((externalState) => { const unsubscribe = externalStore.subscribe((externalState) => {

View File

@ -2,7 +2,7 @@
import Composite from '$lib/core/Composite.svelte'; import Composite from '$lib/core/Composite.svelte';
let composite = { let composite = {
id: 'google', id: 'login',
component: 'GoogleAuth', component: 'GoogleAuth',
services: ['setupLit'] services: ['setupLit']
}; };

View File

@ -2,7 +2,7 @@
import Composite from '$lib/core/Composite.svelte'; import Composite from '$lib/core/Composite.svelte';
let composite = { let composite = {
id: 'composite', id: 'hello',
layout: { layout: {
areas: ` areas: `
"main" "main"
@ -16,10 +16,8 @@
component: 'HelloEarth', component: 'HelloEarth',
slot: 'main', slot: 'main',
map: { map: {
pkpWallet: 'w.pkpWallet', pkpWallet: '@wallet.pkpWallet',
rpcURL: 'w.rpcURL', todos: '@data:queryTodos'
messages: 'data.queryMessages',
todos: 'data.queryTodos'
}, },
services: ['helloEarthAlert'] services: ['helloEarthAlert']
}, },

View File

@ -1,11 +1,8 @@
<script> <script>
import Composite from '$lib/core/Composite.svelte'; import Composite from '$lib/core/Composite.svelte';
import { dataStore } from '$lib/core/dataLoader';
$: console.log('Data Store contents:', $dataStore);
let composite = { let composite = {
id: 'composite', id: 'messages',
layout: { layout: {
areas: ` areas: `
"top top" "top top"
@ -21,7 +18,7 @@
id: 'me', id: 'me',
component: 'Messages', component: 'Messages',
slot: 'main', slot: 'main',
map: { messages: 'data.queryMessages' } map: { messages: '@data:queryMessages' }
}, },
{ {
id: 'terminal', id: 'terminal',

View File

@ -2,7 +2,13 @@
import Composite from '$lib/core/Composite.svelte'; import Composite from '$lib/core/Composite.svelte';
let composite = { let composite = {
id: 'composite', id: 'wallet',
store: {
pkpWallet: '',
rpcURL: 'https://rpc.gnosischain.com/',
pkpPubKey:
'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571'
},
layout: { layout: {
areas: ` areas: `
"top" "top"
@ -18,14 +24,14 @@
slot: 'top' slot: 'top'
}, },
{ {
id: 'wallet', id: 'xyz',
component: 'Wallet', component: 'Wallet',
slot: 'main', slot: 'main',
store: { map: {
pkpWallet: '', rpcURL: '@wallet:rpcURL',
rpcURL: 'https://rpc.gnosischain.com/', pkpPubKey: '@wallet:pkpPubKey',
pkpPubKey: pkpWallet: '@wallet:pkpWallet',
'046da3ba67065fd1e2726242ca01cd4601524893f4aa4b0042578fa6cbec28fa8c9a28eb9f7893932fc09717edc9e1db57e157a21eed346247c1db5a722a01f571' todos: '@data:queryTodos'
} }
}, },
{ {