TinyBase logoTinyBase

destroy

The destroy method should be called when this Relationships 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 Relationships object with a definition (that registers a RowListener with the underlying Store), and then destroys it again, removing the listener.

const store = createStore()
  .setTable('pets', {
    fido: {species: 'dog'},
    felix: {species: 'cat'},
    cujo: {species: 'dog'},
  })
  .setTable('species', {
    wolf: {price: 10},
    dog: {price: 5},
    cat: {price: 4},
  });

const relationships = createRelationships(store);
relationships.setRelationshipDefinition(
  'petSpecies',
  'pets',
  'species',
  'species',
);
console.log(store.getListenerStats().row);
// -> 1

relationships.destroy();

console.log(store.getListenerStats().row);
// -> 0