TinyBase logoTinyBase β

onLocalRowIds

The onLocalRowIds function registers a listener that is called whenever the local Row Ids for a remote Row change.

onLocalRowIds(
  relationshipId: MaybeGetter<IdOrNull>,
  remoteRowId: MaybeGetter<IdOrNull>,
  listener: LocalRowIdsListener,
  relationshipsOrRelationshipsId?: MaybeGetter<undefined | RelationshipsOrRelationshipsId>,
): void
TypeDescription
relationshipIdMaybeGetter<IdOrNull>

The Id of the Relationship, or null to listen to any Relationship.

remoteRowIdMaybeGetter<IdOrNull>

The Id of the remote Row, or null to listen to any remote Row.

listenerLocalRowIdsListener

The function to call when local 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 {onLocalRowIds} from 'tinybase/ui-svelte';

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

  onLocalRowIds('petSpecies', 'dog',
 () => (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', 'felix', 'species', 'dog');
});
flushSync();
console.log(app.textContent);
// -> 'changed'

Since

v8.1.0