TinyBase logoTinyBase β

getSliceIds

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

getSliceIds(
  indexId: MaybeGetter<string>,
  indexesOrIndexesId?: MaybeGetter<undefined | IndexesOrIndexesId>,
): {current: Ids}
TypeDescription
indexIdMaybeGetter<string>

The Id of the Index (or a getter returning it).

indexesOrIndexesId?MaybeGetter<undefined | IndexesOrIndexesId>

The Indexes object to use (plain or getter), 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 {getSliceIds} from 'tinybase/ui-svelte';

  let {indexes} = $props();

  const result = getSliceIds('bySpecies', 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);
// -> '["dog","cat"]'

Since

v8.1.0