hiya, I have some controller and stores that i wan...
# mvikotlin
r
hiya, I have some controller and stores that i want to reuse for a desktop app. and i have made a single
UiComponent
interface with
create()
and
destory()
methods. So now i want to create an essenty lifecycle object that i can pass to my Controller and i can manually call state changes from the create and destroy methods. Is there some prebuilt object in essenty that I can use for this or how would i implement one?
a
Hmm, maybe LifecycleRegistry resume/destroy?
r
Something like this?
Copy code
class RemotesUiComponent:UiComponent{

    // the mvi controller
    private val controller: RemotesController by scope.inject()
    private val lifecycle = LifecycleRegistry()
    override fun create() {
        lifecycle.onCreate()
        lifecycle.onStart()
        lifecycle.onResume()
    }

    override fun destroy() {
        lifecycle.onPause()
        lifecycle.onStop()
        lifecycle.onDestroy()
        scope.close()
    }
}
and i just pass in
lifecycle
to my remotes controller via injection?
a
I would rather pass Lifecycle and avoid create/destroy methods. But this way is also fine. Also, you can call resume/destroy extensions for simplicity.
r
Yes good point I will inject it. Thanks heaps for the help!
👍 1