How to upgrade bluelinelabs/Conductor version 3.1.4 from version 3.0.0

104 views Asked by At

I'm trying to migrate from version 3.0.0 that used conductor-rxlifecycle to version 3.1.4 that is using conductor-archlifecycle and conductor-autodispose.

my current code has extension functions that binds to the lifecycle - and I'm trying to understand what is the code change needed to adjust it to archlifecycle and auto-dispose.

I would appreciate some help here - couldn't figure it out from the demo code.

conductor-archlifecycle demo

conductor-autodispose demo

protected fun <C : RxController> Completable.bindToController(controller: C): Completable =
    observeOn(AndroidSchedulers.mainThread()).compose(controller.bindToLifecycle<Any>())

protected fun <C : RxController> Completable.bindUntil(controller: C, event: ControllerEvent): Completable =
    observeOn(AndroidSchedulers.mainThread()).compose(controller.bindUntilEvent<Any>(event))

I assume that the controller type should be LifecycleController instead of RxController, but I don't understand what is the replacement of bindToLifecycle

I opened this issue , but I'm trying to get some help here as well

1

There are 1 answers

0
Noa Drach On BEST ANSWER

This is the change I did to my code to match the new Conductor version:

The 2 functions above were replaced by this function:

    fun Completable.autoDisposable(event: ControllerEvent? = null): CompletableSubscribeProxy =
    observeOn(AndroidSchedulers.mainThread())
        .autoDisposable(getScopeProvider(event))

Note that the return type is now CompletableSubscribeProxy and not Completable so the location of the call in the chain might need to be changed.

I create different scopes:

    private val scopeProvider: ControllerScopeProvider by lazy { ControllerScopeProvider.from(this) }

    private val destroyScopeProvider: ControllerScopeProvider by lazy {
      ControllerScopeProvider.from(
        this,
        ControllerEvent.DESTROY
      )
    }
...

And this is how getScopeProvider looks

    private fun getScopeProvider(event: ControllerEvent?): ControllerScopeProvider =
    when (event) {
        null -> scopeProvider
        ControllerEvent.DETACH -> detachScopeProvider
        ControllerEvent.DESTROY_VIEW -> destroyViewScopeProvider
        ControllerEvent.DESTROY -> destroyScopeProvider
        else -> throw RuntimeException("Scope for event ${event.name} wasn't created")
    }