provideCheckpoints
The provideCheckpoints function registers a Checkpoints object with a given Id into the current Provider context.
provideCheckpoints(
checkpointsId: string,
checkpoints: Checkpoints,
): void| Type | Description | |
|---|---|---|
checkpointsId | string | The |
checkpoints | Checkpoints | The |
| returns | void | This has no return value. |
Example
This example registers a TinyBase object dynamically in a Provider context.
Registrar.svelte
<svelte:options runes={true} />
<script>
import {provideCheckpoints} from 'tinybase/ui-svelte';
let {checkpoints} = $props();
provideCheckpoints('registered', checkpoints);
</script>
Reader.svelte
<svelte:options runes={true} />
<script>
import {getCheckpointsIds} from 'tinybase/ui-svelte';
const ids = getCheckpointsIds();
</script>
{JSON.stringify(getCheckpointsIds().current)}
App.svelte
<svelte:options runes={true} />
<script>
import {Provider} from 'tinybase/ui-svelte';
import Reader from './Reader.svelte';
import Registrar from './Registrar.svelte';
let {checkpoints} = $props();
</script>
<Provider>
<Registrar {checkpoints} />
<Reader />
</Provider>
import {flushSync, mount} from 'svelte';
import {createCheckpoints, createStore} from 'tinybase';
import App from './App.svelte';
const store = createStore().setCell('pets', 'fido', 'species', 'dog');
const checkpoints = createCheckpoints(store);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {checkpoints}}));
flushSync();
console.log(app.textContent);
// -> ' ["registered"]'
Since
v8.1.0