TinyBase logoTinyBase β

onLinkedRowIds

The onLinkedRowIds function registers a listener that is called whenever the linked Row Ids for a first Row change.

onLinkedRowIds(
  relationshipId: MaybeGetter<string>,
  firstRowId: MaybeGetter<string>,
  listener: LinkedRowIdsListener,
  relationshipsOrRelationshipsId?: MaybeGetter<undefined | RelationshipsOrRelationshipsId>,
): void
TypeDescription
relationshipIdMaybeGetter<string>

The Id of the Relationship.

firstRowIdMaybeGetter<string>

The Id of the first Row.

listenerLinkedRowIdsListener

The function to call when linked Row Ids change.

relationshipsOrRelationshipsId?MaybeGetter<undefined | RelationshipsOrRelationshipsId>

The Relationships object to use, or its Id.

returnsvoid

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 {onLinkedRowIds} from 'tinybase/ui-svelte';

  let {relationships} = $props();
  let seen = $state('');

  onLinkedRowIds('nextPet', 'fido', () => (seen = 'changed'), relationships);
</script>

{seen}
import {flushSync, mount} from 'svelte';
import {createRelationships, 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 relationships = createRelationships(store)
  .setRelationshipDefinition('petSpecies', 'pets', 'species', 'species')
  .setRelationshipDefinition('nextPet', 'pets', 'pets', 'next');
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {relationships}}));
flushSync(() => {
  store.setCell('pets', 'fido', 'next', 'rex');
});
flushSync();
console.log(app.textContent);
// -> 'changed'

Since

v8.1.0