pixelmund / svemix

The Full-Stack addition to SvelteKit. Write your server code inside svelte files, handle sessions, forms and SEO easily.
https://svemix.com
MIT License
336 stars 16 forks source link

Svemix Context #42

Closed pixelmund closed 2 years ago

pixelmund commented 2 years ago

This PR implements a Svemix Context, the context is created by transforming the generated root.svelte file from SvelteKit, so we have to make sure to update this if something changes in Kit.

We're now having access to the loaderData and actionData from any component via the new getLoaderData and getActionData functions in the app which is kinda neat. The old way is ofc still supported.

Example:

<script context="module" lang="ts" ssr>
    import type { Loader } from 'svemix';

    interface LoaderData {
        name: string;
        age: number;
        country: string;
    }

    export const loader: Loader<LoaderData> = () => ({
        name: 'Svemix',
        age: 25,
        country: 'Github'
    });
</script>

<script lang="ts">
    import { getLoaderData } from 'svemix';
    const data = getLoaderData<LoaderData>();
</script>

<h1>{$data.name}</h1>
<h2>{$data.age}</h2>
<h3>{$data.country}</h3>
vercel[bot] commented 2 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/svemix/svemix/AZSzoVpo9u1SgvGkcjj7RREc8Wz5
✅ Preview: Canceled