-
Notifications
You must be signed in to change notification settings - Fork 16
Home
yatsinar edited this page Jul 16, 2020
·
3 revisions
Welcome to the RxData wiki!
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.
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())
}
)
When memory is empty:
When memory has value empty:
Whole algorithm diagram: