forEachMetric
The forEachMetric method takes a function that it will then call for each Metric in the Metrics object.
forEachMetric(metricCallback: MetricCallback): void| Type | Description | |
|---|---|---|
metricCallback | MetricCallback | The function that should be called for every |
| returns | void | This has no return value. |
This method is useful for iterating over all the Metrics in a functional style. The metricCallback parameter is a MetricCallback function that will be called with the Id of each Metric and its value.
Example
This example iterates over each Metric in a Metrics object.
import {createMetrics, createStore} from 'tinybase';
const store = createStore().setTable('species', {
dog: {price: 5},
cat: {price: 4},
worm: {price: 1},
});
const metrics = createMetrics(store)
.setMetricDefinition('highestPrice', 'species', 'max', 'price')
.setMetricDefinition('lowestPrice', 'species', 'min', 'price');
metrics.forEachMetric((metricId, metric) => {
console.log([metricId, metric]);
});
// -> ['highestPrice', 5]
// -> ['lowestPrice', 1]
Since
v1.0.0