TinyBase logoTinyBase β

getIndexIds

The getIndexIds function returns a reactive object reflecting the Ids of the Indexes in an Indexes object, and registers a listener so that any changes will update current.

getIndexIds(indexesOrIndexesId?: MaybeGetter<undefined | IndexesOrIndexesId>): {current: Ids}
TypeDescription
indexesOrIndexesId?MaybeGetter<undefined | IndexesOrIndexesId>

The Indexes object to use, or its Id.

returns{current: Ids}

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

  let {indexes} = $props();

  const result = getIndexIds(indexes);
</script>

{JSON.stringify(result.current)}
import {flushSync, mount} from 'svelte';
import {createIndexes, 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 indexes = createIndexes(store).setIndexDefinition(
  'bySpecies',
  'pets',
  'species',
);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {indexes}}));
console.log(app.textContent);
// -> '["bySpecies"]'

Since

v8.1.0