getMetricIds
The getMetricIds function returns a reactive object reflecting the Ids of the Metrics in a Metrics object, and registers a listener so that any changes will update current.
getMetricIds(metricsOrMetricsId?: MaybeGetter<undefined | MetricsOrMetricsId>): {current: Ids}| Type | Description | |
|---|---|---|
metricsOrMetricsId? | MaybeGetter<undefined | MetricsOrMetricsId> | |
| 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 {getMetricIds} from 'tinybase/ui-svelte';
let {metrics} = $props();
const result = getMetricIds(metrics);
</script>
{JSON.stringify(result.current)}
import {flushSync, mount} from 'svelte';
import {createMetrics, 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 metrics = createMetrics(store).setMetricDefinition(
'speciesPrice',
'species',
'sum',
'price',
);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {metrics}}));
console.log(app.textContent);
// -> '["speciesPrice"]'
Since
v8.1.0