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 d4a4400
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 18 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 @@ -26,7 +26,7 @@ class AndroidUpdateScheduler<Value : Any>(
*/
private var isUpdating = false

private val updateRunnable = object :Runnable {
private val updateRunnable = object : Runnable {
override fun run() {
updateScheduled.set(false)

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 d4a4400

Please sign in to comment.