TinyBase logoTinyBase β

getIndexes

The getIndexes function returns the default Indexes object from the current Provider context (or a named one if an Id is provided).

getIndexes(id?: string): Indexes | undefined
TypeDescription
id?string

An optional Id of a named Indexes object in the Provider context.

returnsIndexes | undefined

The Indexes object, or undefined if not found.

Example

This example reads a TinyBase object from Svelte context inside a child component.

Child.svelte
<svelte:options runes={true} />

<script>
  import {getIndexes} from 'tinybase/ui-svelte';
</script>

{getIndexes()?.getSliceRowIds('bySpecies', 'dog')?.join(',')}
App.svelte
<svelte:options runes={true} />

<script>
  import {Provider} from 'tinybase/ui-svelte';
  import Child from './Child.svelte';

  let {indexes} = $props();
</script>

<Provider {indexes}>
  <Child />
</Provider>
import {flushSync, mount} from 'svelte';
import {createIndexes, createStore} from 'tinybase';
import App from './App.svelte';

const store = createStore().setCell('pets', 'fido', 'species', 'dog');
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);
// -> 'fido'

Since

v8.1.0