added loading and passing of svelte state stores to the machine context
This commit is contained in:
		| @@ -1,23 +1,17 @@ | |||||||
| <script> | <script> | ||||||
| 	import { onMount } from 'svelte'; |  | ||||||
| 	import { coreServices } from '$lib/core/refactor/coreServices'; |  | ||||||
|  |  | ||||||
| 	export let me; | 	export let me; | ||||||
| 	export let data; | 	export let data; | ||||||
|  |  | ||||||
| 	onMount(() => { |  | ||||||
| 		// coreServices.mutateData('ComposerCharly', { hello: ' this is on mount ' }); |  | ||||||
| 	}); |  | ||||||
| 	function toggle() { | 	function toggle() { | ||||||
| 		me.do.machine.send('TOGGLE'); | 		me.do.machine.send('TOGGLE'); | ||||||
| 	} | 	} | ||||||
| </script> | </script> | ||||||
|  |  | ||||||
| <div class="border-2 border-green-500"> | <div class="w-full h-full border-2 border-green-500"> | ||||||
| 	<p>My ID is: {me.id}</p> | 	<p>My ID is: {me.id}</p> | ||||||
| 	my state is {$data.state} | 	my state is {$data.state} | ||||||
| 	<h1 class="h1">I am charly</h1> | 	<h1 class="h1">I am charly</h1> | ||||||
| 	my data.context prop: {JSON.stringify($data.context)} | 	my data.context.hello prop: {JSON.stringify($data.context.hello)} | ||||||
| 	<br /> | 	<br /> | ||||||
| 	<button | 	<button | ||||||
| 		class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700" | 		class="px-4 py-2 font-bold text-white bg-blue-500 rounded hover:bg-blue-700" | ||||||
| @@ -25,8 +19,11 @@ | |||||||
| 	> | 	> | ||||||
| 		Toggle | 		Toggle | ||||||
| 	</button> | 	</button> | ||||||
|  | 	<div class="p-8 overflow-scroll h-1/2"> | ||||||
| 	<!-- {#each $data.context.messages as message (message.timestamp)} | 		{#if $data.context.messages} | ||||||
|  | 			{#each $data.context.messages as message} | ||||||
| 				<p>{message.text}</p> | 				<p>{message.text}</p> | ||||||
| 	{/each} --> | 			{/each} | ||||||
|  | 		{/if} | ||||||
|  | 	</div> | ||||||
| </div> | </div> | ||||||
|   | |||||||
| @@ -1,8 +1,8 @@ | |||||||
| <script lang="ts"> | <script lang="ts"> | ||||||
| 	import Composer from '$lib/core/refactor/Composer.svelte'; | 	import Composer from '$lib/core/refactor/Composer.svelte'; | ||||||
| 	import { assign } from 'xstate'; | 	import { assign } from 'xstate'; | ||||||
| 	import { coreServices } from '$lib/core/refactor/coreServices'; |  | ||||||
| 	import { queryMessages } from '$lib/data/queryMessages'; | 	import { queryMessages } from '$lib/data/queryMessages'; | ||||||
|  | 	import { get } from 'svelte/store'; | ||||||
|  |  | ||||||
| 	let composer = { | 	let composer = { | ||||||
| 		id: 'ComposerParent', | 		id: 'ComposerParent', | ||||||
| @@ -39,12 +39,12 @@ | |||||||
| 					}, | 					}, | ||||||
| 					states: { | 					states: { | ||||||
| 						LOADING: { | 						LOADING: { | ||||||
|  | 							entry: assign({ | ||||||
|  | 								messages: (context, event) => get(queryMessages) | ||||||
|  | 							}), | ||||||
| 							on: { | 							on: { | ||||||
| 								TOGGLE: { | 								TOGGLE: { | ||||||
| 									target: 'READY', | 									target: 'READY' | ||||||
| 									actions: assign({ |  | ||||||
| 										hello: (context, event) => 'this was updated from loading' |  | ||||||
| 									}) |  | ||||||
| 								} | 								} | ||||||
| 							} | 							} | ||||||
| 						}, | 						}, | ||||||
|   | |||||||
| @@ -2,14 +2,14 @@ | |||||||
| import { getComposerStore } from './composerStores'; | import { getComposerStore } from './composerStores'; | ||||||
|  |  | ||||||
| export const coreServices = { | export const coreServices = { | ||||||
|     mutateData: (storeID: string, value: any) => { |     // mutateData: (storeID: string, value: any) => { | ||||||
|         const store = getComposerStore(storeID); |     //     const store = getComposerStore(storeID); | ||||||
|         console.log(`mutateData called with storeID: ${storeID} and value: ${JSON.stringify(value)}`); |     //     console.log(`mutateData called with storeID: ${storeID} and value: ${JSON.stringify(value)}`); | ||||||
|         store.update(storeData => { |     //     store.update(storeData => { | ||||||
|             storeData.context = value; |     //         storeData.context = value; | ||||||
|             return storeData; |     //         return storeData; | ||||||
|         }); |     //     }); | ||||||
|     }, |     // }, | ||||||
|     subscribeData: (storeID: string) => { |     subscribeData: (storeID: string) => { | ||||||
|         const store = getComposerStore(storeID); |         const store = getComposerStore(storeID); | ||||||
|         return store; |         return store; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user