https://kotlinlang.org logo
#ballast
Title
# ballast
r

rocketraman

11/08/2023, 10:16 PM
@Casey Brooks I'm upgrading from v2 to v4 and I used to have an interceptor which used
BallastNotification.ViewModelStarted
to send an initial input to the view model queue. What would the replacement be now that there is no
ViewModelStarted
option. I see
ViewModelStatusChanged
, and I can do
if (it.status == Status.Running)
but I see that
Status.Running
is in an internal package. Is there a better approach now?
c

Casey Brooks

11/08/2023, 10:20 PM
notificationFlow.awaitViewModelStart()
is what you should be using. It does exactly what you described https://github.com/copper-leaf/ballast/blob/main/ballast-api/src/commonMain/kotlin/com/copperleaf/ballast/utils.kt#L276
r

rocketraman

11/08/2023, 10:21 PM
Like this?
Copy code
launch(start = CoroutineStart.UNDISPATCHED) {
      notifications.awaitViewModelStart()
      val initialInput = initialInputFn()
      sendToQueue(Queued.HandleInput(null, initialInput))
    }
c

Casey Brooks

11/08/2023, 10:23 PM
Yup, that’s exactly right. But even better, you can just use
BootstrapInterceptor
if that’s all you’re doing with the interceptor https://github.com/copper-leaf/ballast/blob/main/ballast-utils/src/commonMain/kotlin/com/copperleaf/ballast/core/BootstrapInterceptor.kt
r

rocketraman

11/08/2023, 10:23 PM
Oh nice, thank you.