diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityStoreContextImpl.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityStoreContextImpl.kt index 2cedb393..f64694c7 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityStoreContextImpl.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/ActivityStoreContextImpl.kt @@ -71,10 +71,12 @@ internal class ActivityStoreContextImpl : ActivityS } override fun send(effect: Activity.() -> Unit) { - Utils.executeOnMainThread { - // We allow emitting effects only after activity has started - startedActivity()?.effect() ?: run { - // Log missing activity. + // We allow emitting effects only after activity has started + if (Utils.isMainThread()) { + startedActivity()?.effect() + } else { + Utils.mainThreadHandler.post { + startedActivity()?.effect() } } } diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/CompositeBinding.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/CompositeBinding.kt index 162614f7..5fce0125 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/CompositeBinding.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/CompositeBinding.kt @@ -72,10 +72,7 @@ internal class CompositeBinding( override fun types(): Set> = types override fun binds(key: Any): Boolean { - bindings.forEachIndices { - if (it.binds(key)) return true - } - return false + return types.contains(key.javaClass) } override fun bind(context: FormulaContext<*, *>, input: Input) { diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/FeatureBinding.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/FeatureBinding.kt index 763c3a27..6ef7bf65 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/FeatureBinding.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/FeatureBinding.kt @@ -1,6 +1,5 @@ package com.instacart.formula.android.internal -import android.os.SystemClock import com.instacart.formula.Action import com.instacart.formula.Evaluation import com.instacart.formula.Formula diff --git a/formula-android/src/main/java/com/instacart/formula/android/internal/Utils.kt b/formula-android/src/main/java/com/instacart/formula/android/internal/Utils.kt index c122ea7c..3a1dc740 100644 --- a/formula-android/src/main/java/com/instacart/formula/android/internal/Utils.kt +++ b/formula-android/src/main/java/com/instacart/formula/android/internal/Utils.kt @@ -12,14 +12,6 @@ internal object Utils { } } - inline fun executeOnMainThread(crossinline runnable: () -> Unit) { - if (isMainThread()) { - runnable() - } else { - mainThreadHandler.post { runnable() } - } - } - fun isMainThread(): Boolean { return Looper.getMainLooper() == Looper.myLooper() }