This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionListViewModelImpl( | |
private val getTransactionsUseCase: GetTransactionsUseCase //typealias | |
) : TransactionListViewModel, ViewModel() { | |
private val compositeDisposable = CompositeDisposable() | |
override val state = MutableLiveData<State>() | |
override fun loadTransactions() { | |
state.postValue(State.Loading) | |
getTransactionsUseCase().subscribeBy { handleResult(it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyDaggerModule { | |
@Provides | |
fun provideGetTransactionsUseCase( | |
private val userRepository: UserRepository, | |
private val transactionRepository: TransactionRepository | |
): GetTransactionsUseCase { | |
return { | |
getTransactions( | |
userRepository::getUser, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class FPGetTransactionUseCaseFactory( | |
private val userRepository: UserRepository, | |
private val transactionRepository: TransactionRepository | |
) { | |
fun makeGetTransactionsUseCase(): GetTransactionsUseCase { | |
return { | |
getTransactions( | |
userRepository::getUser, | |
transactionRepository |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TransactionListViewModelImpl( | |
private val getTransactionsUseCase: GetTransactionsUseCase //interface | |
) : TransactionListViewModel, ViewModel() { | |
private val compositeDisposable = CompositeDisposable() | |
override val state = MutableLiveData<State>() | |
override fun loadTransactions() { | |
state.postValue(State.Loading) | |
getTransactionsUseCase().subscribeBy { handleResult(it) } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetUserUseCaseImpl( | |
private val userRepository: UserRepository | |
) : GetUserUseCase { | |
override fun invoke(): User = userRepository.getUser() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interface TransactionRepository { | |
fun getTransactions(userId: String): Single<SimpleResult<List<Transaction>>> | |
} | |
interface UserRepository { | |
fun getUser(): User |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun getTransactions( | |
getUserUseCase: GetUserUseCase, | |
transactionRepository: TransactionRepository | |
): Single<SimpleResult<List<Transaction>>> { | |
return transactionRepository.getTransactions(getUserUseCase().id) | |
} | |
typealias GetTransactionsUseCase = () -> Single<SimpleResult<List<Transaction>>> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GetTransactionsUseCaseImpl( | |
private val getUserUseCase: GetUserUseCase, | |
private val transactionRepository: TransactionRepository | |
) : GetTransactionsUseCase { | |
override fun invoke(): Single<SimpleResult<List<Transaction>>> { | |
return transactionRepository.getTransactions(getUserUseCase().id) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object FPRepositoryFactory { | |
fun makeAlbumRepository(): AlbumRepository { | |
return AlbumRepositoryImpl( | |
AlbumApiServiceImpl(), | |
makeAlbumDataMapper() | |
) | |
} | |
private fun makeAlbumDataMapper(): (NetworkAlbum) -> Album = { albumDto -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object OOPRepositoryFactory { | |
fun makeAlbumRepository(): AlbumRepository { | |
return AlbumRepositoryImpl( | |
AlbumApiServiceImpl(), | |
AlbumDataMapper(NullableInputListMapperImpl(SongDataMapper())) | |
) | |
} | |
} |