CXwudi / realworld-compose-http4k-example-app

WIP Conduit (https://github.com/gothinkster/realworld) example app developed in Compose Multiplatform and Http4k
https://realworld.io
MIT License
0 stars 0 forks source link

We need POC of frontend architecture #1

Open CXwudi opened 1 week ago

CXwudi commented 1 week ago

Back in song finder vocab app, we made an innovative architecture based on DI and MVVM. We introduced a new concept called state model that basically shares state values between multiple view model. However the architecture lacks proper handling of navigation, android configuration change, etc.

Question: can DI and state model things still works using MVIKotlin and Decompose?

CXwudi commented 1 week ago

Decompose works, next on MVIKotlin and configuration change

CXwudi commented 1 week ago

MVIKotlin and configuration change data restoration succeed. The MVIKotlin and Decompose libraries are so well designed that it is so robust and feature-rich yet extendible.

Next move on to the last missing piece of puzzle: Koin

CXwudi commented 6 days ago

Koin initial PoC result:

  1. Not possible to let Koin manage all the Decompose component
    • Reason: because each component can create it child component, hence the component will need the koin instance for getting dependencies. If you don't want the component to hold a Koin instance, then the component need to know the callback for creating each dependency. This can be done in koin using like single { SomeComponent() { get<AnotherComponent>()} }. However, once again the AnotherComponent can possible also need another callback. Hence a chain of callback is unavoidable and hence not possible to let Koin manage all the Decompose component creation.
  2. Better to create the first DefaultComponentContext by hand
    • Reason: it is possible to do it with Koin, but given the Decompose documentation, you better not to. Instead, create a initKoin() function that pass the DefaultComponentContext into it would be a feasible solution
CXwudi commented 6 days ago

Move on to next and the last POC 😄: Sharing services or classes with multiple Decompose component

Be aware of the LifeCycle and Android condiguration change thing

CXwudi commented 5 days ago

Successfully finished all PoC 🎉🎉🎉

The Koin looks like can survive configuration change, and so does all dependencies inside Koin, because we created a service without any handling of configuration changes, but it is still surviving. First guess is that androidContext {} call in koinApplication {} makes all dependencies survive we need to ask a question in koin slack to see why my dependencies survive the configuration change

CXwudi commented 4 days ago

Koin slack confirm that something is happening causing the unexpected surviving behaviour. We need a minimal reproducible sample, without Decompose and mvikotlin involved.