Skip to content

Commit

Permalink
fix: StaffDataRepository.staff getter returns new instance each calls
Browse files Browse the repository at this point in the history
  • Loading branch information
amay077 committed May 23, 2018
1 parent 85e278a commit 73ff982
Showing 1 changed file with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import io.github.droidkaigi.confsched2018.data.local.LocalJsonParser
import io.github.droidkaigi.confsched2018.data.local.StaffJsonMapper
import io.github.droidkaigi.confsched2018.model.Staff
import io.github.droidkaigi.confsched2018.util.rx.SchedulerProvider
import io.reactivex.BackpressureStrategy
import io.reactivex.Completable
import io.reactivex.Flowable
import io.reactivex.Single
import io.reactivex.subjects.BehaviorSubject
import timber.log.Timber
import javax.inject.Inject

Expand All @@ -18,16 +19,16 @@ class StaffDataRepository @Inject constructor(
) : StaffRepository {
@CheckResult override fun loadStaff(): Completable = getStaff()
.subscribeOn(schedulerProvider.io())
.toCompletable()

override val staff: Flowable<List<Staff>>
get() = getStaff().toFlowable().subscribeOn(schedulerProvider.io())
private val sender = BehaviorSubject.createDefault<List<Staff>>(emptyList())
override val staff : Flowable<List<Staff>> = sender.toFlowable(BackpressureStrategy.LATEST)

@CheckResult private fun getStaff(): Single<List<Staff>> {
return Single.create { emitter ->
@CheckResult private fun getStaff(): Completable {
return Completable.create { emitter ->
try {
val asset = LocalJsonParser.loadJsonFromAsset(context, "staff.json")
emitter.onSuccess(StaffJsonMapper.mapToStaffList(asset))
sender.onNext(StaffJsonMapper.mapToStaffList(asset))
emitter.onComplete()
} catch (e: Exception) {
Timber.e(e)
emitter.onError(e)
Expand Down

0 comments on commit 73ff982

Please sign in to comment.