TinyBase logoTinyBase β

onRemoteRowId

The onRemoteRowId function registers a listener that is called whenever the remote Row Id for a local Row changes.

onRemoteRowId(
  relationshipId: MaybeGetter<IdOrNull>,
  localRowId: MaybeGetter<IdOrNull>,
  listener: RemoteRowIdListener,
  relationshipsOrRelationshipsId?: MaybeGetter<undefined | RelationshipsOrRelationshipsId>,
): void
TypeDescription
relationshipIdMaybeGetter<IdOrNull>

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

localRowIdMaybeGetter<IdOrNull>

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

listenerRemoteRowIdListener

The function to call when the remote Row Id changes.

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

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

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

Since

v8.1.0