TinyBase logoTinyBase β

startAutoPersisting

The startAutoPersist method is a convenience method that starts both automatic loading and saving of the Store data.

startAutoPersisting(
  initialContent?: Content | () => Content,
  startSaveFirst?: boolean,
): Promise<SessionPersister>
TypeDescription
initialContent?Content | () => Content

An optional Content object used when the underlying storage has not previously been populated.

startSaveFirst?boolean

Whether to start saving before loading, defaulting to false.

returnsPromise<SessionPersister>

A Promise containing a reference to the Persister object.

This simply runs the startAutoLoad and startAutoSave methods in sequence, and returns a Promise that resolves when both have completed.

This method can take initialContent to pass to the startAutoLoad method. See its documentation for more details.

If for some reason you want to start saving before you start loading, pass true as the second parameter.

Example

and saving.

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

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

await persister.startAutoPersisting();
console.log(persister.isAutoSaving());
// -> true
console.log(persister.isAutoLoading());
// -> true

persister.destroy();

Since

v6.1.0