saveStatePlugin
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:
MapSaver for saving partial data.
TypedSaver for saving a state of a particular subtype.
JsonSaver for saving the state as a JSON.
FileSaver for saving the state to a file. See DefaultFileSaver for custom file writing logic.
CompressedFileSaver for saving the state to a file and compressing it.
CallbackSaver for logging.
NoOpSaver for testing.
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.