RxDataStoreBuilder
class RxDataStoreBuilder<T>
kotlin.Any | |
↳ | androidx.datastore.rxjava3.RxDataStoreBuilder |
RxSharedPreferencesMigrationBuilder class for a DataStore that works on a single process.
Summary
Public constructors | |
---|---|
<init>(produceFile: Callable<File>, serializer: Serializer<T>) Create a RxDataStoreBuilder with the callable which returns the File that DataStore acts on. |
|
<init>(context: Context, fileName: String, serializer: Serializer<T>) Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file. |
Public methods | |
---|---|
RxDataStoreBuilder<T> |
addDataMigration(dataMigration: DataMigration<T>) Add a DataMigration to the Datastore. |
RxDataStoreBuilder<T> |
addRxDataMigration(rxDataMigration: RxDataMigration<T>) Add an RxDataMigration to the DataStore. |
DataStore<T> |
build() Build the DataStore. |
RxDataStoreBuilder<T> |
setCorruptionHandler(corruptionHandler: ReplaceFileCorruptionHandler<T>) Sets the corruption handler to install into the DataStore. |
RxDataStoreBuilder<T> |
setIoScheduler(ioScheduler: Scheduler) Set the Scheduler on which to perform IO and transform operations. |
Public constructors
<init>
RxDataStoreBuilder(
produceFile: Callable<File>,
serializer: Serializer<T>)
Create a RxDataStoreBuilder with the callable which returns the File that DataStore acts on. The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.
Parameters | |
---|---|
produceFile: Callable<File> | Function which returns the file that the new DataStore will act on. The function must return the same path every time. No two instances of DataStore should act on the same file at the same time. |
serializer: Serializer<T> | the serializer for the type that this DataStore acts on. |
<init>
RxDataStoreBuilder(
context: Context,
fileName: String,
serializer: Serializer<T>)
Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by See Context.createDataStore for more info. The user is responsible for ensuring that there is never more than one DataStore acting on a file at a time.
Parameters | |
---|---|
context: Context | the context from which we retrieve files directory. |
fileName: String | 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. |
serializer: Serializer<T> | the serializer for the type that this DataStore acts on. |
Public methods
addDataMigration
fun addDataMigration(dataMigration: DataMigration<T>): RxDataStoreBuilder<T>
Add a DataMigration to the Datastore. Migrations are run in the order they are added.
Parameters | |
---|---|
dataMigration: DataMigration<T> | the migration to add |
Return | |
---|---|
this |
addRxDataMigration
fun addRxDataMigration(rxDataMigration: RxDataMigration<T>): RxDataStoreBuilder<T>
Add an RxDataMigration to the DataStore. Migrations are run in the order they are added.
Parameters | |
---|---|
rxDataMigration: RxDataMigration<T> | the migration to add. |
Return | |
---|---|
this |
build
fun build(): DataStore<T>
Build the DataStore.
Return | |
---|---|
the DataStore with the provided parameters |
setCorruptionHandler
fun setCorruptionHandler(corruptionHandler: ReplaceFileCorruptionHandler<T>): RxDataStoreBuilder<T>
Sets the corruption handler to install into the DataStore.
This parameter is optional and defaults to no corruption handler.
Parameters | |
---|---|
corruptionHandler: ReplaceFileCorruptionHandler<T> |
Return | |
---|---|
this |
setIoScheduler
fun setIoScheduler(ioScheduler: Scheduler): RxDataStoreBuilder<T>
Set the Scheduler on which to perform IO and transform operations. This is converted into a CoroutineDispatcher before being added to DataStore.
This parameter is optional and defaults to Schedulers.io().
Parameters | |
---|---|
ioScheduler: Scheduler | the scheduler on which IO and transform operations are run |
Return | |
---|---|
this |