resolveCheckpoints
The resolveCheckpoints function is used to get a reference to a Checkpoints object from a Provider context, or have it passed directly.
resolveCheckpoints(checkpointsOrCheckpointsId?: MaybeGetter<undefined | CheckpointsOrCheckpointsId>): () => Checkpoints | undefined| Type | Description | |
|---|---|---|
checkpointsOrCheckpointsId? | MaybeGetter<undefined | CheckpointsOrCheckpointsId> | The |
| returns | () => Checkpoints | undefined | A getter function returning the |
Example
This example reads a TinyBase object from Svelte context inside a child component.
Child.svelte
<svelte:options runes={true} />
<script>
import {resolveCheckpoints, getCheckpointsIds} from 'tinybase/ui-svelte';
</script>
{JSON.stringify(resolveCheckpoints('petCheckpoints')()?.getCheckpointIds())}
App.svelte
<svelte:options runes={true} />
<script>
import {Provider} from 'tinybase/ui-svelte';
import Child from './Child.svelte';
let {checkpoints} = $props();
</script>
<Provider checkpointsById={{petCheckpoints: checkpoints}}>
<Child />
</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}}));
console.log(app.textContent);
// -> '[[],"0",[]]'
Since
v8.1.0