onCheckpointIds
The onCheckpointIds function registers a listener that is called whenever the Checkpoint Ids change.
onCheckpointIds(
listener: CheckpointIdsListener,
checkpointsOrCheckpointsId?: MaybeGetter<undefined | CheckpointsOrCheckpointsId>,
): void| Type | Description | |
|---|---|---|
listener | CheckpointIdsListener | The function to call when Checkpoint |
checkpointsOrCheckpointsId? | MaybeGetter<undefined | CheckpointsOrCheckpointsId> | The |
| returns | void | This has no return value. |
Example
This example registers a Svelte listener and responds to a TinyBase change.
App.svelte
<svelte:options runes={true} />
<script>
import {onCheckpointIds} from 'tinybase/ui-svelte';
let {checkpoints} = $props();
let seen = $state('');
onCheckpointIds(() => (seen = 'changed'), checkpoints);
</script>
{seen}
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}}));
flushSync(() => {
store.setCell('pets', 'fido', 'species', 'guide dog');
checkpoints.addCheckpoint('saved');
});
flushSync();
console.log(app.textContent);
// -> 'changed'
Since
v8.1.0