TinyBase logoTinyBase β

MetricView

MetricView(
  this: void,
  props: MetricViewProps,
): {
  $on?: (type: string, callback: (e: any) => void): () => void;
  $set?: (props: Partial<MetricViewProps>): void;
}
TypeDescription
thisvoid
propsMetricViewProps

The props passed to the component.

returns{ $on?: (type: string, callback: (e: any) => void): () => void; $set?: (props: Partial<MetricViewProps>): void; }

Example

This example creates TinyBase objects outside the component and renders the Svelte component with them.

App.svelte
<script>
  import {MetricView} from 'tinybase/ui-svelte';

  export let metrics;
</script>

<MetricView metricId="petCount" {metrics} />
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(
  'petCount',
  'pets',
  'count',
);
const app = document.body.appendChild(document.createElement('div'));
flushSync(() => mount(App, {target: app, props: {metrics}}));
console.log(app.textContent);
// -> '2'

Since

v8.1.0