getSliceRowIds
The getSliceRowIds function returns a reactive object reflecting the Ids of the Rows in a Slice, and registers a listener so that any changes will update current.
getSliceRowIds(
indexId: MaybeGetter<string>,
sliceId: MaybeGetter<string>,
indexesOrIndexesId?: MaybeGetter<undefined | IndexesOrIndexesId>,
): {current: Ids}| Type | Description | |
|---|---|---|
indexId | MaybeGetter<string> | |
sliceId | MaybeGetter<string> | |
indexesOrIndexesId? | MaybeGetter<undefined | IndexesOrIndexesId> | |
| returns | {current: Ids} | A reactive object with a |
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 {getSliceRowIds} from 'tinybase/ui-svelte';
let {indexes} = $props();
const result = getSliceRowIds('bySpecies', 'dog', 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);
// -> '["fido"]'
Since
v8.1.0