TinyBase logoTinyBase

delListener

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

delListener(listenerId: string): this
TypeDescription
listenerIdstring

The Id of the listener to remove.

returnsthis

A reference to the Persister.

Use the Id returned by whichever method was used to add the listener. Note that the Persister may re-use this Id for future listeners added to it.

Example

This example registers a listener and then removes it.

import {createSessionPersister} from 'tinybase/persisters/persister-browser';
import {createStore} from 'tinybase';

const persister = createSessionPersister(createStore(), 'pets');

const listenerId = persister.addStatusListener((_persister, status) => {
  console.log(`Status changed to ${status}`);
});

await persister.load();
// -> `Status changed to 1`
// -> `Status changed to 0`

persister.delListener(listenerId);

await persister.load();
// -> undefined
// The listener is not called.

Since

v5.3.0