TinyBase logoTinyBase β

stopAutoLoad

The stopAutoLoad method stops the automatic loading of data from storage previously started with the startAutoLoad method.

stopAutoLoad(): Promise<FilePersister>
returnsPromise<FilePersister>

A Promise containing a reference to the Persister object.

If the Persister is not currently set to automatically load, this method has no effect. This method is asynchronous.

Example

This example creates an empty Store, and starts automatically loading data into it from the browser's session storage. Once the automatic loading is stopped, subsequent changes are not reflected in the Store.

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

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

// In another browser tab:
sessionStorage.setItem('pets', '[{"pets":{"toto":{"species":"dog"}}},{}]');
// -> StorageEvent('storage', {storageArea: sessionStorage, key: 'pets'})
// ...
console.log(store.getTables());
// -> {pets: {toto: {species: 'dog'}}}

await persister.stopAutoLoad();

// In another browser tab:
sessionStorage.setItem(
  'pets',
  '[{"pets":{"felix":{"species":"cat"}}},{}]',
);
// -> StorageEvent('storage', {storageArea: sessionStorage, key: 'pets'})
// ...
console.log(store.getTables());
// -> {pets: {toto: {species: 'dog'}}}
// Storage change has not been automatically loaded.

await persister.destroy();
sessionStorage.clear();

Since

v1.0.0