Saver

interface Saver<T>

A Saver is an object that specifies how to save the state of the saveStatePlugin. See docs for specific functions to learn how to override them.

Functions

Link copied to clipboard
open suspend fun recover(e: Exception): T?

recover allows to return a state to save and restore even if an exception has been caught while the saver was working. By default, it just throws the exception and the parent store will decide how to handle it.

Link copied to clipboard
abstract suspend fun restore(): T?

restore function should restore the state from the storage. It could be a file, a bundle on Android, or some other place. State is restored before the store starts, so it is not advised to suspend in this function for very long periods of time. If this function returns null, the state will not be restored (there is nothing to restore).

Link copied to clipboard
abstract suspend fun save(state: T?)

save function should persist the state to some place that outlives the lifespan of the store If null is passed to save, it must clean up the persisted state completely. You must adhere to this contract if you implement your own saver.