added core default services to our composite

This commit is contained in:
Samuel Andert 2023-07-27 16:33:55 +02:00
parent b546a22302
commit 049fae15e5
5 changed files with 43 additions and 18 deletions

View File

@ -7,6 +7,10 @@
$: if (services && services.helloEarthAlert) {
// services.helloEarthAlert.alertMe();
}
$: if (services.core) {
console.log('services: ' + JSON.stringify(services));
// services.core.testAlert();
}
$: if ($store) isStoreLoaded = true;
</script>
@ -14,9 +18,15 @@
{#if isStoreLoaded}
<div class="p-12 bg-blue-400 rounded-md shadow-lg">
<p class="mb-4 text-xl font-bold text-white">Hello Earth</p>
Wallet Address:
{#if $store.pkpWallet}
<p class="mb-6 text-white">Wallet Address: {$store.pkpWallet.address}</p>
<p class="mb-6 text-white">{$store.pkpWallet.address}</p>
{/if}
<br />
hello store: {#if $store.hello}{$store.hello}{/if}
<br />
hello store2: {#if $store.hello2}{$store.hello2}{/if}
<br />
Reference TodoList
{#if $store.todos}
<ul class="pl-5 list-decimal">

View File

@ -5,6 +5,7 @@
import services from '$lib/core/servicesLoader';
import { dataStore } from '$lib/core/dataLoader';
import { createCompositeStore, getCompositeStore } from '$lib/core/compositeStores';
import { coreServices } from './coreServices';
interface ICompositeLayout {
areas: string;
@ -27,7 +28,9 @@
}
export let composite: IComposite;
let loadedServices: Record<string, any> = {};
let loadedServices: Record<string, any> = {
core: coreServices
};
let layoutStyle = '';
$: {

View File

@ -0,0 +1,18 @@
// coreServices.ts
import { getCompositeStore } from './compositeStores';
export const coreServices = {
updateStore: (mappings: Record<string, string>) => {
for (const [mappingString, value] of Object.entries(mappings)) {
const [storeID, key] = mappingString.replace('@', '').split(':');
const store = getCompositeStore(storeID);
store.update(storeData => {
storeData[key] = value;
return storeData;
});
}
},
testAlert: () => {
alert("core service alert")
}
};

View File

@ -1,6 +1,6 @@
// dataLoader.ts
import { writable } from 'svelte/store';
import dataSources from 'virtual:data-sources-list'; // Import the generated list
import dataSources from 'virtual:data-sources-list';
// The store that holds the data sets
export const dataStore = writable({});
@ -14,17 +14,3 @@ dataSources.forEach(src => {
dataStore.update(store => ({ ...store, [src]: moduleData }));
});
});
// // dataLoader.ts
// import { writable } from 'svelte/store';
// import { queryMessages } from '$lib/data/queryMessages';
// import { queryTodos } from '$lib/data/queryTodos';
// // The store that holds the data sets
// export const dataStore = writable({
// queryMessages: queryMessages,
// queryTodos: queryTodos
// });

View File

@ -3,6 +3,9 @@
let composite = {
id: 'hello',
store: {
helloMapMe: 'this is going to be mapped'
},
layout: {
areas: `
"main"
@ -12,10 +15,15 @@
},
children: [
{
id: 'hello',
id: 'earth',
component: 'HelloEarth',
slot: 'main',
store: {
hello: 'define me directly',
hello2: 'overwrite me with the mapping value'
},
map: {
hello2: '@hello.helloMapMe',
pkpWallet: '@wallet.pkpWallet',
todos: '@data:queryTodos'
},