TinyBase logoTinyBase

delListener

The delListener method removes a listener that was previously added to the Metrics object.

delListener(listenerId: Id): Metrics
TypeDescription
listenerIdId

The Id of the listener to remove.

returnsMetrics

A reference to the Metrics object.

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.

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',
  (metrics, metricId, newMetric, oldMetric) => {
    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.