Skip to content

Commit

Permalink
Updates some stuff related to loggers
Browse files Browse the repository at this point in the history
  • Loading branch information
cjbrooks12 committed Mar 24, 2022
1 parent fcd5b0f commit f58d5da
Show file tree
Hide file tree
Showing 35 changed files with 303 additions and 183 deletions.
31 changes: 20 additions & 11 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,24 @@
## 0.13.0

- Renames `ballast-crashlytics` module to `ballast-firebase-crashlytics`
- Fixes issue where JS Debugger cannot connect because browser websocket clients can't send headers
- **BREAKING CHANGE:** Renames `sideEffect()` to `sideJob()` to be more accurate and less confusing in comparison to
other Kotlin MVI libraries
- SideJobs are now posted to the VM immediately, rather than collected and dispatched explicitly after handling.
## 0.13.0 - 2022-03-24

- [BREAKING CHANGE] Renames `ballast-crashlytics` module to `ballast-firebase-crashlytics`
- [BREAKING CHANGE] Renames `sideEffect()` to `sideJob()` to be more accurate and less confusing in comparison to
other Kotlin MVI libraries.
- [BREAKING CHANGE] `BallastViewModel` no longer implements the `SendChannel` interface, it exposes the `send` and
`trySend` methods directly. It also adds `sendAndAwaitCompletion()` to send an Input and wait for it to completely
finish processing.
- [BREAKING CHANGE] The `logger` property of `BallastViewModelConfiguration.Builder` is now a function, which receives
the viewModel name when built, to pass as the tag of a logger.
- [BREAKING CHANGE] Moves annotations for Firebase into commonMain and renames them:
- `@FirebaseCrashlyticsInterceptor.Ignore` --> `@FirebaseCrashlyticsIgnore`
- `@FirebaseAnalyticsInterceptor.TrackInput` --> `@FirebaseAnalyticsTrackInput`
- [FUNCTIONAL CHANGE] SideJobs are now posted to the VM immediately, rather than collected and dispatched explicitly
after handling. The default implementation still requires that SideJobs are sent as the last statements of the
`InputHandler`, though.
- By writing a custom `InputStrategy.Guardian`, you could remove the restriction that sideJobs must be started at the
end of the Input, and potentially actually call `sideJob()` and wait for the sideJob to start before continuing.
This is dangerous and should not be taken lightly, but it is now possible, whereas it was not before.
- `BallastViewModel` no longer implements the `SendChannel` interface, it exposes the `send` and `trySend` methods
directly. It also adds `sendAndAwaitCompletion()` to send an Input and wait for it to completely finish processing.
end of the Input. This is dangerous and you shouldn't do it unless you really know what you're doing.
- [BUG FIX] Fixes issue where JS Debugger cannot connect because JS browser websocket clients can't send headers
- [NEW] Adds platform-specific `BallastLogger` implementations (`AndroidBallastLogger`, `JsConsoleBallastLogger`). The
default logger of `BallastViewModelConfiguration` is still `NoOpLogger()`.

## 0.12.0 - 2022-03-17

Expand Down
21 changes: 14 additions & 7 deletions ballast-core/api/android/ballast-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ public abstract interface class com/copperleaf/ballast/BallastViewModelConfigura

public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component11 ()Lcom/copperleaf/ballast/BallastLogger;
public final fun component11 ()Lkotlin/jvm/functions/Function1;
public final fun component2 ()Ljava/lang/Object;
public final fun component3 ()Lcom/copperleaf/ballast/InputHandler;
public final fun component4 ()Lcom/copperleaf/ballast/InputFilter;
Expand All @@ -208,8 +208,8 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun component7 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component8 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component9 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun copy (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public static synthetic fun copy$default (Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;ILjava/lang/Object;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public final fun copy (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public static synthetic fun copy$default (Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public fun equals (Ljava/lang/Object;)Z
public final fun getEventsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getFilter ()Lcom/copperleaf/ballast/InputFilter;
Expand All @@ -219,7 +219,7 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun getInputsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getInterceptorDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getInterceptors ()Ljava/util/List;
public final fun getLogger ()Lcom/copperleaf/ballast/BallastLogger;
public final fun getLogger ()Lkotlin/jvm/functions/Function1;
public final fun getName ()Ljava/lang/String;
public final fun getSideJobsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public fun hashCode ()I
Expand All @@ -230,7 +230,7 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun setInputStrategy (Lcom/copperleaf/ballast/InputStrategy;)V
public final fun setInputsDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun setInterceptorDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun setLogger (Lcom/copperleaf/ballast/BallastLogger;)V
public final fun setLogger (Lkotlin/jvm/functions/Function1;)V
public final fun setName (Ljava/lang/String;)V
public final fun setSideJobsDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public fun toString ()Ljava/lang/String;
Expand Down Expand Up @@ -349,6 +349,13 @@ public final class com/copperleaf/ballast/UtilsKt {
public static final fun postInput (Lcom/copperleaf/ballast/InputHandlerScope;Ljava/lang/Object;)V
}

public final class com/copperleaf/ballast/core/AndroidBallastLogger : com/copperleaf/ballast/BallastLogger {
public fun <init> (Ljava/lang/String;)V
public fun debug (Ljava/lang/String;)V
public fun error (Ljava/lang/Throwable;)V
public fun info (Ljava/lang/String;)V
}

public class com/copperleaf/ballast/core/AndroidViewModel : androidx/lifecycle/ViewModel, com/copperleaf/ballast/BallastViewModel {
public fun <init> (Lcom/copperleaf/ballast/BallastViewModelConfiguration;)V
public final fun attachEventHandler (Landroidx/lifecycle/LifecycleOwner;Lcom/copperleaf/ballast/EventHandler;)V
Expand Down
14 changes: 7 additions & 7 deletions ballast-core/api/jvm/ballast-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -195,11 +195,11 @@ public abstract interface class com/copperleaf/ballast/BallastViewModelConfigura

public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder {
public fun <init> ()V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;)V
public synthetic fun <init> (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/String;
public final fun component10 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component11 ()Lcom/copperleaf/ballast/BallastLogger;
public final fun component11 ()Lkotlin/jvm/functions/Function1;
public final fun component2 ()Ljava/lang/Object;
public final fun component3 ()Lcom/copperleaf/ballast/InputHandler;
public final fun component4 ()Lcom/copperleaf/ballast/InputFilter;
Expand All @@ -208,8 +208,8 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun component7 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component8 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun component9 ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun copy (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public static synthetic fun copy$default (Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lcom/copperleaf/ballast/BallastLogger;ILjava/lang/Object;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public final fun copy (Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public static synthetic fun copy$default (Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;Ljava/lang/String;Ljava/lang/Object;Lcom/copperleaf/ballast/InputHandler;Lcom/copperleaf/ballast/InputFilter;Ljava/util/List;Lcom/copperleaf/ballast/InputStrategy;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlinx/coroutines/CoroutineDispatcher;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Lcom/copperleaf/ballast/BallastViewModelConfiguration$Builder;
public fun equals (Ljava/lang/Object;)Z
public final fun getEventsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getFilter ()Lcom/copperleaf/ballast/InputFilter;
Expand All @@ -219,7 +219,7 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun getInputsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getInterceptorDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public final fun getInterceptors ()Ljava/util/List;
public final fun getLogger ()Lcom/copperleaf/ballast/BallastLogger;
public final fun getLogger ()Lkotlin/jvm/functions/Function1;
public final fun getName ()Ljava/lang/String;
public final fun getSideJobsDispatcher ()Lkotlinx/coroutines/CoroutineDispatcher;
public fun hashCode ()I
Expand All @@ -230,7 +230,7 @@ public final class com/copperleaf/ballast/BallastViewModelConfiguration$Builder
public final fun setInputStrategy (Lcom/copperleaf/ballast/InputStrategy;)V
public final fun setInputsDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun setInterceptorDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public final fun setLogger (Lcom/copperleaf/ballast/BallastLogger;)V
public final fun setLogger (Lkotlin/jvm/functions/Function1;)V
public final fun setName (Ljava/lang/String;)V
public final fun setSideJobsDispatcher (Lkotlinx/coroutines/CoroutineDispatcher;)V
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.copperleaf.ballast.core

import android.util.Log
import com.copperleaf.ballast.BallastLogger

public class AndroidBallastLogger(private val tag: String) : BallastLogger {
override fun debug(message: String) {
Log.d(tag, message)
}

override fun info(message: String) {
Log.i(tag, message)
}

override fun error(throwable: Throwable) {
Log.e(tag, null, throwable)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ public interface BallastViewModelConfiguration<Inputs : Any, Events : Any, State
public var eventsDispatcher: CoroutineDispatcher = Dispatchers.Default,
public var sideJobsDispatcher: CoroutineDispatcher = Dispatchers.Default,
public var interceptorDispatcher: CoroutineDispatcher = Dispatchers.Default,
public var logger: BallastLogger = NoOpLogger(),
public var logger: (String) -> BallastLogger = { NoOpLogger() },
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ private fun <Inputs : Any, Events : Any, State : Any> List<BallastInterceptor<*,

public fun <Inputs : Any, Events : Any, State : Any> BallastViewModelConfiguration.Builder.build(
): BallastViewModelConfiguration<Inputs, Events, State> {
val vmName = name ?: "$inputHandler-vm"
return DefaultViewModelConfiguration<Inputs, Events, State>(
initialState = initialState.requireTyped("initialState"),
inputHandler = inputHandler.requireTyped("inputHandler"),
Expand All @@ -163,8 +164,8 @@ public fun <Inputs : Any, Events : Any, State : Any> BallastViewModelConfigurati
eventsDispatcher = eventsDispatcher,
sideJobsDispatcher = sideJobsDispatcher,
interceptorDispatcher = interceptorDispatcher,
name = name ?: "$inputHandler-vm",
logger = logger,
name = vmName,
logger = logger(vmName),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,16 @@ import kotlin.coroutines.EmptyCoroutineContext

public open class IosViewModel<Inputs : Any, Events : Any, State : Any> private constructor(
private val impl: BallastViewModelImpl<Inputs, Events, State>,
private val eventHandler: EventHandler<Inputs, Events, State>,
coroutineScope: CoroutineScope,
) : BallastViewModel<Inputs, Events, State> by impl {

final override val type: String = "IosViewModel"

public constructor(
config: BallastViewModelConfiguration<Inputs, Events, State>,
eventHandler: EventHandler<Inputs, Events, State>,
coroutineScope: CoroutineScope = CoroutineScope(EmptyCoroutineContext),
) : this(
BallastViewModelImpl(config),
eventHandler,
coroutineScope
)

Expand All @@ -34,7 +31,10 @@ public open class IosViewModel<Inputs : Any, Events : Any, State : Any> private
/**
* Observe the changes to state and emitted events from an iOS ViewController. Corresponds to `onStart` in Android
*/
public fun onViewWillAppear(onStateChanged: (State) -> Unit) {
public fun onViewWillAppear(
eventHandler: EventHandler<Inputs, Events, State>,
onStateChanged: (State) -> Unit,
) {
impl.viewModelScope.launch {
impl.observeStates().collect { onStateChanged(it) }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.copperleaf.ballast.examples.web.internal
package com.copperleaf.ballast.core

import com.copperleaf.ballast.BallastLogger

class JsConsoleLogger : BallastLogger {
public class JsConsoleBallastLogger : BallastLogger {
override fun debug(message: String) {
console.log(message)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,11 @@ class BallastCoreTests {
eventHandler = TestEventHandler(),
filter = TestInputFilter(),
) {
skip()
defaultInitialState { State() }

scenario("update string value only") {

running {
+Inputs.UpdateStringValue("one")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ public final class com/copperleaf/ballast/debugger/idea/BallastIdeaPlugin {
public fun <init> ()V
}

public final class com/copperleaf/ballast/debugger/idea/IntellijPluginBallastLogger : com/copperleaf/ballast/BallastLogger {
public static final field $stable I
public fun <init> (Lcom/intellij/openapi/diagnostic/Logger;)V
public fun debug (Ljava/lang/String;)V
public fun error (Ljava/lang/Throwable;)V
public fun info (Ljava/lang/String;)V
}

public abstract class com/copperleaf/ballast/debugger/idea/base/ComposeSettings : com/intellij/openapi/options/Configurable {
public static final field $stable I
public fun <init> ()V
Expand Down
Loading

0 comments on commit f58d5da

Please sign in to comment.