Hello again. I need to create a repository for a ...
# mvikotlin
f
Hello again. I need to create a repository for a bluetooth connection. The bluetooth connection depends on a scope, that is, as long as the scope is valid, the connection remains active. I need this connection to be active for multiple screens. I thought about creating a store/component with application scope and sharing it with each screen. It's possible? Do you see another way to do this?
I am trying in this way
Copy code
sealed class Child {
    data class Foo(
        val component: FooComponent,
        val commonComponent: CommonComponent
    ) : Child()

    data class Dummy(
        val component: DummyComponent,
        val peripheralComponent: CommonComponent
    ) : Child()
}
any news I post here
a
Hello! From the first sight it seems you can just create a usual interface/class and scope it in your root (activity/app/whatever). And then just pass it down to all required components via constructors.
Or you can scope it in the Root component. You can also use
InstanceKeeper
there, if you need it to survive configuration changes on Android.
f
Copy code
Or you can scope it in the Root component. You can also use InstanceKeeper there, if you need it to survive configuration changes on Android.
I liked this approach. For now I've created a new component, and if it works I'll try your approach as well. Thinking about it, maybe I'll leave it with the component, as it has a store, I can keep the connection state and update the screens that observe it.
a
Yeah. Please note that components are normal classes as well. The only possible difference is if you need a
ComponentContext
for it, in which case you will need to use either
childContext(...)
or
Router
.
f
Got it, maybe using a component to do what I need is overkill. Perhaps the best is to use only one store and scope it in the Root component.
a
Depends on the API you want. If you need Store and it will be useful to deal with in other places, then go for it.