saveStatePlugin

fun <S : MVIState, I : MVIIntent, A : MVIAction> saveStatePlugin(saver: Saver<S>, context: CoroutineContext = EmptyCoroutineContext, name: String? = PluginNameSuffix, behaviors: Set<SaveBehavior> = SaveBehavior.Default, resetOnException: Boolean = true): LazyPlugin<S, I, A>

Creates a plugin for persisting and restoring MVIState of the current store.

This function takes a Saver as a parameter, which it will use for determining how and where to save the state. Savers can be decorated and extended to implement your own logic. There are a couple of default savers:

The plugin will determine when to save the state based on behaviors. Please see SaveBehavior documentation for more details. this function will throw if the behaviors are empty.

  • If resetOnException is true, the plugin will attempt to clear the state if an exception is thrown.

  • All state saving is done in a background coroutine.

  • The state restoration, however, is done before the store starts. This means that while the state is being restored, the store will not process intents and state changes.

  • The installation order of this plugin is very important. If other plugins, installed after this one, change the state in StorePlugin.onStart, your restored state may be overwritten.

See also