delListener
The delListener
method removes a listener that was previously added to the Metrics
object.
delListener(listenerId: string): Metrics
Type | Description | |
---|---|---|
listenerId | string | The |
returns | Metrics | A reference to the |
Use the Id
returned by the addMetricListener
method. Note that the Metrics
object may re-use this Id
for future listeners added to it.
Example
This example creates a Store
, a Metrics
object, registers a listener, and then removes it.
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');
const listenerId = metrics.addMetricListener('highestPrice', () => {
console.log('highestPrice metric changed');
});
store.setCell('species', 'horse', 'price', 20);
// -> 'highestPrice metric changed'
metrics.delListener(listenerId);
store.setCell('species', 'giraffe', 'price', 50);
// -> undefined
// The listener is not called.
Since
v1.0.0