Skip to content
yatsinar edited this page Jul 16, 2020 · 3 revisions

Welcome to the RxData wiki!

Getting Started

Gradle is the only supported build configuration - please add the below line to your build.gradle:

implementation 'com.revolut.rxdata:dod:1.2.5'
implementation 'com.revolut.rxdata:core:1.2.8'

DOD, hereinafter stands for DataObservableDelegate, module contains DataObservableDelegate class and depends on core itself. Core might be required separately if in some modules e.g. in domain you need to work with Data Streams, but don't need the DOD itself.

Data Streams here and below will stand for any Observable<Data> stream, which originate from DOD.

Examples

Here is the very basic DOD implementation:

private val observePortfolio: DataObservableDelegate<String, Portfolio> = DataObservableDelegate(
    fromNetwork = {
        tradingService.getPortfolio()
            .map { portfolioDto ->
                portfolioDto.toDomain(stocksConfig)
            }         
    },
    fromMemory = { memoryCache[PORTFOLIO] },
    toMemory = { _, portfolio ->
      memoryCache[PORTFOLIO] = portfolio
    },
    fromStorage = {
      portfolioDao.getMainPortfolio()?.toDomain()
    },
    toStorage = { _, portfolio ->
      portfolioDao.savePortfolio(portfolioEntity = portfolio.toDb())
    }
)

Lifecycle

When memory is empty:

Memory is Empty

When memory has value empty:

Whole algorithm diagram:

Clone this wiki locally