Skip to content

Commit

Permalink
Add a bunch of tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
Laimiux committed Jan 25, 2024
1 parent 4b60bc6 commit 675363d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ internal class ActivityStoreContextImpl<Activity : FragmentActivity> : 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()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,7 @@ internal class CompositeBinding<ParentComponent, ScopedComponent>(
override fun types(): Set<Class<*>> = 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<ParentComponent>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down

0 comments on commit 675363d

Please sign in to comment.