Add ModelsViewModel and ModelService for fetching AnyLogic model metadata#501
Add ModelsViewModel and ModelService for fetching AnyLogic model metadata#501
Conversation
|
|
||
| object AnyLogicModelsRepository { | ||
| private val service = ModelService() | ||
| var models by mutableStateOf<List<AnyLogicModel>>(emptyList()) |
There was a problem hiding this comment.
I found in the LanguageManager that this is does not trigger a re-render. Probably because it is not in the Composable tree.
There was a problem hiding this comment.
Not sure how to explain this but if it is read inside a composable, it will trigger a recomposition.
and i know the basic rule is that when a composable reads a State<T> during composition and that state changes, compose re-renders.
If you never read it in composition, nothing happens.
| suspend fun getAllModels(): List<AnyLogicModel> | ||
| } | ||
|
|
||
| class ModelService( |
There was a problem hiding this comment.
Usually the "Repository" is simple and the "Service" more complex. But here it is the other way around
There was a problem hiding this comment.
Maybe the confusion comes from mixing backend naming conventions with frontend/Kobweb architecture? 🧐 I don't see anything wrong with the setup itself, hmm
|
I wonder if we can have a more pure implementation of the ViewModel pattern like in https://github.com/google-developer-training/basic-android-kotlin-compose-training-unscramble/tree/main/app/src/main/java/com/example/unscramble/ui Put the state in compositionLocal so it can be accessed from all the ModelCard components. Like I do with the LanguageProvider: |
|
Please let me know if we're kind of on the same page. |
|
I wonder if we should enrich the "TwinModel" objects before rendering, or if the logic should be put in the card components (and in individual model pages) |
|
Im inclined to agree with having the state in compositionLocal, while i worked this, co-pilot suggested this approach and i thought it was a bit too much.
I think enriching |
Ok I mostly wanted to know what you'll build on top of this. Will approve this PR. |
|
New changes aligns with ViewModel pattern, i envision how we can also enrich |
No description provided.