-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move main thread scheduler to FragmentFlowStore.
- Loading branch information
Showing
5 changed files
with
51 additions
and
21 deletions.
There are no files selected for viewing
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
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
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
29 changes: 29 additions & 0 deletions
29
...a-android/src/main/java/com/instacart/formula/android/internal/FeatureObservableAction.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.instacart.formula.android.internal | ||
|
||
import com.instacart.formula.Action | ||
import com.instacart.formula.Cancelable | ||
import com.instacart.formula.android.Feature | ||
import com.instacart.formula.android.FragmentEnvironment | ||
import com.instacart.formula.android.FragmentId | ||
import io.reactivex.rxjava3.core.Observable | ||
|
||
class FeatureObservableAction( | ||
private val fragmentEnvironment: FragmentEnvironment, | ||
private val fragmentId: FragmentId, | ||
private val feature: Feature<*>, | ||
) : Action<Any> { | ||
|
||
override fun key(): Any = fragmentId | ||
|
||
override fun start(send: (Any) -> Unit): Cancelable { | ||
val observable = feature.state.onErrorResumeNext { | ||
fragmentEnvironment.onScreenError(fragmentId.key, it) | ||
Observable.empty() | ||
} | ||
|
||
// We ensure all feature state updates come on the main thread. | ||
val androidUpdateScheduler = AndroidUpdateScheduler(send) | ||
val disposable = observable.subscribe(androidUpdateScheduler::emitUpdate) | ||
return Cancelable(disposable::dispose) | ||
} | ||
} |
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