destroy
The destroy
method should be called when this Persister
object is no longer used.
destroy(): this
returns | this |
---|
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.
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 {createSessionPersister} from 'tinybase/persisters/persister-browser';
import {createStore} from 'tinybase';
const store = createStore();
const persister = createSessionPersister(store, 'pets');
await persister.startAutoSave();
console.log(store.getListenerStats().transaction);
// -> 1
persister.destroy();
console.log(store.getListenerStats().transaction);
// -> 0
Since
v1.0.0