DataStoreDelegate
class DataStoreDelegate
A reusable holder that owns a single DataStore instance for a DevView module.
Each module that requires persistent storage should declare one instance of this class. The DataStore is initialised lazily on the first call to init, which is triggered automatically by rememberModules for any module implementing RequiresDataStore. The null guard inside init ensures the DataStore is created exactly once per process regardless of recompositions.
Usage
Declare a single instance on the module object or as a top-level val if the DataStore must be shared across multiple modules (e.g. a Ktor plugin and a UI panel that need the same DataStore):
Module-owned delegate
object MyModule : Module, RequiresDataStore {
override val dataStoreName = "my_module.preferences_pb"
override val dataStoreDelegate = DataStoreDelegate()
}Content copied to clipboard
Shared top-level delegate
// In the shared core module
public val myModuleDataStoreDelegate = DataStoreDelegate()
// In the UI module
object MyModule : Module, RequiresDataStore {
override val dataStoreName = "my_module.preferences_pb"
override val dataStoreDelegate = myModuleDataStoreDelegate
}
// In the Ktor plugin module
val dataStore = myModuleDataStoreDelegate.get()Content copied to clipboard
See also
Functions
Link copied to clipboard
Returns the initialised DataStore instance.
Link copied to clipboard
Initialises the DataStore instance for the given dataStoreName.