destroy
The destroy
method should be called when this Queries
object is no longer used.
destroy(): void
This guarantees that all of the listeners that the object registered with the underlying Store
are removed and it can be correctly garbage collected.
Example
This example creates a Store
, adds a Queries
object with a definition (that registers a RowListener
with the underlying Store
), and then destroys it again, removing the listener.
import {createQueries, createStore} from 'tinybase';
const store = createStore().setTable('pets', {
fido: {species: 'dog'},
felix: {species: 'cat'},
cujo: {species: 'dog'},
});
const queries = createQueries(store);
queries.setQueryDefinition('species', 'species', ({select}) => {
select('species');
});
console.log(store.getListenerStats().row);
// -> 1
queries.destroy();
console.log(store.getListenerStats().row);
// -> 0
Since
v2.0.0