TinyBase logoTinyBase β

getCheckpoints

The getCheckpoints function returns the default Checkpoints object from the current Provider context (or a named one if an Id is provided).

getCheckpoints(id?: string): Checkpoints | undefined
TypeDescription
id?string

An optional Id of a named Checkpoints object in the Provider context.

returnsCheckpoints | undefined

The Checkpoints object, or undefined if not found.

Example

This example reads a TinyBase object from Svelte context inside a child component.

Child.svelte
<svelte:options runes={true} />

<script>
  import {getCheckpoints} from 'tinybase/ui-svelte';
</script>

{JSON.stringify(getCheckpoints()?.getCheckpointIds())}
App.svelte
<svelte:options runes={true} />

<script>
  import {Provider} from 'tinybase/ui-svelte';
  import Child from './Child.svelte';

  let {checkpoints} = $props();
</script>

<Provider {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