Is there a reason why one is not supposed to creat...
# mvikotlin
p
Is there a reason why one is not supposed to create a
store
by calling
storeFactory.create
and instead is supposed to create some factory class with a function returning
object : Store<…> by storeFactory.create(…)
?
There are no strict rules here.
p
I think I get it. When you call
storeFactory::create
directly, it returns an instance of
Store<Intent, State, Label>
and if it’s used together with
instanceKeeper::getStore
you get weird `ClassCastException`s in runtime
a
I wouldn't expect any exceptions, I think it should work fine. A reproducer would be nice to have.
p
Here. I’ve created a sample with coroutines from your decompose-multiplatform-template, just go to WelcomeComponent and it crashes
a
Ah yes thanks! That makes sense actually. The getStore method without arguments uses T::class as key. Since the type is Store and you create two stores under the same InstanceKeeper, it crashes. You need to provide a key for each store in this case, just pass
getStore(key = "store1") { ... }
. I will play with typeOf instead of KClass and see if it solves the issue.
🤔 1
p
Ok, thanks
👍 1
a
Good news! I was able to use
typeOf
instead of
T::KClass
, so it won't crash starting with the next release.
🙌 1