TinyBase logoTinyBase β

getCheckpoint

The getCheckpoint function returns a reactive object reflecting the label of a checkpoint, and registers a listener so that any changes will update current.

getCheckpoint(
  checkpointId: MaybeGetter<string>,
  checkpointsOrCheckpointsId?: MaybeGetter<undefined | CheckpointsOrCheckpointsId>,
): {current: string | undefined}
TypeDescription
checkpointIdMaybeGetter<string>

The Id of the checkpoint (or a getter returning it).

checkpointsOrCheckpointsId?MaybeGetter<undefined | CheckpointsOrCheckpointsId>

The Checkpoints object to use (plain or getter), or its Id.

returns{current: string | undefined}

A reactive object with a current string | undefined property.

Example

This example passes a TinyBase object into a Svelte component and reads the reactive object's current property.

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

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

  let {checkpoints} = $props();

  const result = getCheckpoint('0', checkpoints);
</script>

{result.current ?? ''}
import {flushSync, mount} from 'svelte';
import {createCheckpoints, createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore()
  .setTables({
    pets: {
      fido: {species: 'dog', color: 'brown', sold: false, next: 'felix'},
      felix: {species: 'cat', color: 'black', sold: true},
    },
    species: {dog: {price: 5}, cat: {price: 4}},
  })
  .setValues({open: true, employees: 3});
const checkpoints = createCheckpoints(store);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {checkpoints}}));
console.log(app.textContent);
// -> ''

Since

v8.1.0