TinyBase logoTinyBase β

getCheckpointIds

The getCheckpointIds function returns a reactive object reflecting the CheckpointIds (backward, current, forward) in a Checkpoints object, and registers a listener so that any changes will update current.

getCheckpointIds(checkpointsOrCheckpointsId?: MaybeGetter<undefined | CheckpointsOrCheckpointsId>): {current: CheckpointIds}
TypeDescription
checkpointsOrCheckpointsId?MaybeGetter<undefined | CheckpointsOrCheckpointsId>

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

returns{current: CheckpointIds}

A reactive object with a current CheckpointIds 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 {getCheckpointIds} from 'tinybase/ui-svelte';

  let {checkpoints} = $props();

  const result = getCheckpointIds(checkpoints);
</script>

{JSON.stringify(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);
// -> '[[],"0",[]]'

Since

v8.1.0