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| Type | Description | |
|---|---|---|
id? | string | An optional |
| returns | Indexes | undefined | The |
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