RxDataStoreBuilder


class RxDataStoreBuilderAny>

Builder class for an RxDataStore that works on a single process.

Summary

Public constructors

Any> RxDataStoreBuilder(
    produceFile: Callable<File>,
    serializer: Serializer
)

Create a RxDataStoreBuilder with the callable which returns the File that DataStore acts on.

Any> RxDataStoreBuilder(
    context: Context,
    fileName: String,
    serializer: Serializer
)

Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file.

Public functions

RxDataStoreBuilder

Add a DataMigration to the Datastore.

RxDataStoreBuilder

Add an RxDataMigration to the DataStore.

RxDataStore

Build the DataStore.

RxDataStoreBuilder

Sets the corruption handler to install into the DataStore.

RxDataStoreBuilder
setIoScheduler(ioScheduler: Scheduler)

Set the Scheduler on which to perform IO and transform operations.

Public constructors

RxDataStoreBuilder

Any> RxDataStoreBuilder(
    produceFile: Callable<File>,
    serializer: Serializer
)

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

the serializer for the type that this DataStore acts on.

RxDataStoreBuilder

Any> RxDataStoreBuilder(
    context: Context,
    fileName: String,
    serializer: Serializer
)

Create a RxDataStoreBuilder with the Context and name from which to derive the DataStore file. The file is generated by File(this.filesDir, "datastore/$fileName"). 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.applicationContext.filesDir that DataStore acts on. The File is obtained from dataStoreFile. It is created in the "/datastore" subdirectory.

serializer: Serializer

the serializer for the type that this DataStore acts on.

Public functions

addDataMigration

Added in 1.0.0
fun addDataMigration(dataMigration: DataMigration): RxDataStoreBuilder

Add a DataMigration to the Datastore. Migrations are run in the order they are added.

Parameters
dataMigration: DataMigration

the migration to add

Returns
RxDataStoreBuilder

this

addRxDataMigration

Added in 1.0.0
fun addRxDataMigration(rxDataMigration: RxDataMigration): RxDataStoreBuilder

Add an RxDataMigration to the DataStore. Migrations are run in the order they are added.

Parameters
rxDataMigration: RxDataMigration

the migration to add.

Returns
RxDataStoreBuilder

this

build

Added in 1.0.0
fun build(): RxDataStore

Build the DataStore.

Returns
RxDataStore

the DataStore with the provided parameters

setCorruptionHandler

Added in 1.0.0
fun setCorruptionHandler(
    corruptionHandler: ReplaceFileCorruptionHandler
): RxDataStoreBuilder

Sets the corruption handler to install into the DataStore.

This parameter is optional and defaults to no corruption handler.

Parameters
corruptionHandler: ReplaceFileCorruptionHandler
Returns
RxDataStoreBuilder

this

setIoScheduler

Added in 1.0.0
fun setIoScheduler(ioScheduler: Scheduler): RxDataStoreBuilder

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

Returns
RxDataStoreBuilder

this