diff --git a/formula-android-tests/src/test/java/com/instacart/formula/FragmentFlowRenderViewTest.kt b/formula-android-tests/src/test/java/com/instacart/formula/FragmentFlowRenderViewTest.kt index 7f50a911..333c8a4b 100644 --- a/formula-android-tests/src/test/java/com/instacart/formula/FragmentFlowRenderViewTest.kt +++ b/formula-android-tests/src/test/java/com/instacart/formula/FragmentFlowRenderViewTest.kt @@ -10,8 +10,6 @@ import com.google.common.truth.Truth.assertThat import com.instacart.formula.android.FragmentFlowState import com.instacart.formula.android.FragmentKey import com.instacart.formula.android.BackCallback -import com.instacart.formula.android.FragmentEnvironment -import com.instacart.formula.rxjava3.toObservable import com.instacart.formula.test.TestKey import com.instacart.formula.test.TestKeyWithId import com.instacart.formula.test.TestFragmentActivity diff --git a/formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxAction.kt b/formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxAction.kt index 172ffdea..70d091c6 100644 --- a/formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxAction.kt +++ b/formula-rxjava3/src/main/java/com/instacart/formula/rxjava3/RxAction.kt @@ -20,17 +20,10 @@ interface RxAction : Action { * } * ``` */ - inline fun fromObservable( - crossinline create: () -> Observable + fun fromObservable( + create: () -> Observable ): Action { - return object : RxAction { - - override fun observable(): Observable { - return create() - } - - override fun key(): Any = Unit - } + return fromObservable(Unit, create) } /** @@ -45,18 +38,11 @@ interface RxAction : Action { * * @param key Used to distinguish this [Action] from other actions. */ - inline fun fromObservable( + fun fromObservable( key: Any?, - crossinline create: () -> Observable + create: () -> Observable ): Action { - return object : RxAction { - - override fun observable(): Observable { - return create() - } - - override fun key(): Any? = key - } + return RxActionImpl(key, create) } } @@ -67,3 +53,16 @@ interface RxAction : Action { return Cancelable(disposable::dispose) } } + +private data class RxActionImpl( + private val key: Any?, + private val factory: () -> Observable +): RxAction { + override fun observable(): Observable { + return factory() + } + + override fun key(): Any? { + return key + } +} \ No newline at end of file diff --git a/formula/src/test/java/com/instacart/formula/rxjava3/RxJavaRuntimeTest.kt b/formula/src/test/java/com/instacart/formula/rxjava3/RxJavaRuntimeTest.kt new file mode 100644 index 00000000..2a47873e --- /dev/null +++ b/formula/src/test/java/com/instacart/formula/rxjava3/RxJavaRuntimeTest.kt @@ -0,0 +1,33 @@ +package com.instacart.formula.rxjava3 + +import com.instacart.formula.RuntimeConfig +import com.instacart.formula.test.CountingInspector +import com.instacart.formula.types.InputIdentityFormula +import io.reactivex.rxjava3.core.Observable +import org.junit.Test + +class RxJavaRuntimeTest { + + @Test fun `toObservable with unit input and no config`() { + val formula = InputIdentityFormula() + formula.toObservable().test().assertValues(Unit) + } + + @Test fun `toObservable with unit input and config`() { + val inspector = CountingInspector() + val config = RuntimeConfig(inspector = inspector) + val formula = InputIdentityFormula() + formula.toObservable(config).test().assertValues(Unit) + inspector.assertEvaluationCount(1) + } + + @Test fun `toObservable with integer input and no config`() { + val formula = InputIdentityFormula() + formula.toObservable(0).test().assertValues(0) + } + + @Test fun `toObservable with observable input and no config`() { + val formula = InputIdentityFormula() + formula.toObservable(Observable.just(0, 1, 2)).test().assertValues(0, 1, 2) + } +} \ No newline at end of file