getMetric
The getMetric
method gets the current value of a Metric
.
getMetric(metricId: Id): undefined | number
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).
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