0.0.3 • Published 2 years ago

turbo-storage v0.0.3

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

Usage

...

Provider

<script>
	import { Provider } from 'turbo-storage/provider';
</script>

<Provider.Host consumers={['https://domain.com']} />

Consumer

recommended initialize in +layout.ts.

import { createConsumer } from '$lib/consumer';
import { consumer } from '../stores/consumer';
import type { LayoutLoad } from './$types';
import { PUBLIC_CONSUMER_URL } from '$env/static/public';

export const ssr = false;
export const prerender = true;

export const load: LayoutLoad = () => {
	consumer.set(createConsumer(PUBLIC_CONSUMER_URL));
};

we using svelte storages

Persist data

The persist function recive an object with any keys and values. The values can be primitives or complex.

await $consumer.persist({ count: 0, darkMode: false });

Obtain data

The obtain function recive n string args.

const { count, darkMode } = await $consumer.obtain('count', 'darkMode');

The obtain function detect of arguments and build object returned with unknown values.

(method) Consumser.obtain<["key"]>(keys_0: "key"): Promise<{
    key: unknown;
}>

After. we recommend validates values of response. Where the validate function return value with type

const count = validateCount(storagedCount);

Delete data

To delete keys of storage, pass null as values in persist function.

await $consumer.persist({ count: null, darkMode: null });