delListener
The delListener
method removes a listener that was previously added to the Relationships
object.
delListener(listenerId: string): Relationships
Type | Description | |
---|---|---|
listenerId | string | The |
returns | Relationships | A reference to the |
Use the Id
returned by whichever method was used to add the listener. Note that the Relationships
object may re-use this Id
for future listeners added to it.
Example
This example creates a Store
, a Relationships
object, registers a listener, and then removes it.
import {createRelationships, createStore} from 'tinybase';
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',
);
const listenerId = relationships.addLocalRowIdsListener(
'petSpecies',
'dog',
() => {
console.log('petSpecies relationship (to dog) changed');
},
);
store.setRow('pets', 'toto', {species: 'dog'});
// -> 'petSpecies relationship (to dog) changed'
relationships.delListener(listenerId);
store.setRow('pets', 'toto', {species: 'dog'});
// -> undefined
// The listener is not called.
Since
v1.0.0