getMetric
The getMetric
method gets the current value of a Metric
.
getMetric(metricId: string): undefined | number
Type | Description | |
---|---|---|
metricId | string | |
returns | undefined | number | The numeric value of the |
If the identified Metric
does not exist (or if the definition references a Table
or Cell
value that does not exist) then undefined
is returned.
Example
This example creates a Store
, creates a Metrics
object, and defines a simple Metric
to average the price values in the Table
. It then uses getMetric to access its value (and also the value of a Metric
that has not been defined).
import {createMetrics, createStore} from 'tinybase';
const store = createStore().setTable('species', {
dog: {price: 5},
cat: {price: 4},
worm: {price: 1},
});
const metrics = createMetrics(store);
metrics.setMetricDefinition('highestPrice', 'species', 'max', 'price');
console.log(metrics.getMetric('highestPrice'));
// -> 5
console.log(metrics.getMetric('lowestPrice'));
// -> undefined
Since
v1.0.0