TinyBase logoTinyBase β

destroy

The destroy method should be called when this Persister object is no longer used.

destroy(): Promise<PglitePersister>
returnsPromise<PglitePersister>

A Promise containing a reference to the Persister object.

This guarantees that all of the listeners that the object registered with the underlying Store and storage are removed and it can be correctly garbage collected. It is equivalent to running the stopAutoLoad method and the stopAutoSave method in succession. This method is asynchronous.

Example

This example creates a Store, associates a Persister object with it (that registers a TablesListener with the underlying Store), and then destroys it again, removing the listener.

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

const store = createStore();
const persister = createSessionPersister(store, 'pets');
await persister.startAutoSave();

console.log(store.getListenerStats().transaction);
// -> 1

await persister.destroy();

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

Since

v1.0.0