RxDataStoreDelegateKt
public final class RxDataStoreDelegateKt
Summary
Public methods |
|
|---|---|
static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull RxDataStore<@NonNull T>> |
<T extends Object> rxDataStore(Creates a property delegate for a single process DataStore. |
Public methods
rxDataStore
public static final @NonNull ReadOnlyProperty<@NonNull Context, @NonNull RxDataStore<@NonNull T>> <T extends Object> rxDataStore(
@NonNull String fileName,
@NonNull Serializer<@NonNull T> serializer,
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler,
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations,
@NonNull Scheduler scheduler
)
Creates a property delegate for a single process DataStore. This should only be called once in a file (at the top level), and all usages of the DataStore should use a reference the same Instance. The receiver type for the property delegate must be an instance of Context.
This should only be used from a single application in a single classloader in a single process.
Example usage:
val Context.myRxDataStore by rxDataStore("filename", serializer)
class SomeClass(val context: Context) {
fun update(): Single<Settings> = context.myRxDataStore.updateDataAsync {...}
}
| Parameters | |
|---|---|
@NonNull String fileName |
the filename relative to Context.filesDir that DataStore acts on. The File is obtained by calling File(context.filesDir, "datastore/$fileName")). No two instances of DataStore should act on the same file at the same time. |
@NonNull Serializer<@NonNull T> serializer |
the Serializer to serialize and deserialize on-disk data to type |
ReplaceFileCorruptionHandler<@NonNull T> corruptionHandler |
The corruptionHandler is invoked if DataStore encounters a |
@NonNull Function1<@NonNull Context, @NonNull List<@NonNull DataMigration<@NonNull T>>> produceMigrations |
produce the migrations. The ApplicationContext is passed in to these callbacks as a parameter. DataMigrations are run before any access to data can occur. Each producer and migration may be run more than once whether or not it already succeeded (potentially because another migration failed or a write to disk failed.) |
@NonNull Scheduler scheduler |
The scheduler in which IO operations and transform functions will execute. |
| Returns | |
|---|---|
@NonNull ReadOnlyProperty<@NonNull Context, @NonNull RxDataStore<@NonNull T>> |
a property delegate that manages a datastore as a singleton. |