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<RemotePersister>
Type | Description | |
---|---|---|
initialContent? | Content | () => Content | An optional |
startSaveFirst? | boolean | Whether to start saving before loading, defaulting to false. |
returns | Promise<RemotePersister> | A Promise containing a reference to the |
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