Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the architecture of D-KMP may be too complex? #2

Closed
jiqimaogou opened this issue Apr 14, 2021 · 2 comments
Closed

the architecture of D-KMP may be too complex? #2

jiqimaogou opened this issue Apr 14, 2021 · 2 comments

Comments

@jiqimaogou
Copy link

jiqimaogou commented Apr 14, 2021

if I just write a network request and update the UI. D-KMP has so many concepts:

  1. Events.kt
  2. KMPViewModel.kt
  3. StateManager.kt
  4. StateProviders.kt
  5. StateReducers.kt
  6. Repository.kt

and the relation between these concept is also complex. I think these are hard to maintain.

image

can you simple the architecture of D-KMP, make more less concepts, and less relationship between these concepts.

@dbaroncelli
Copy link
Owner

dbaroncelli commented Apr 14, 2021

Hi @jiqimaogou thanks for your feedback.

I think the most important concept is the separation between the ViewModel and Repository, which is present in all architectures. These are the main 2 blocks.
Specifically, the D-KMP Architecture is implementing the MVI pattern, which requires to organize the ViewModel in a certain way. The MVI pattern helps writing very simple code, but in order to do that you need to give a very neat structure.

The 4 elements in the KMPViewModel are simply:

  • Events, called by the UI layer to perform actions
  • StateProviders, called by the UI layer to get the state for each screen
  • StateReducers, where we define all functions that make modifications to the state (they are always called by the Events)
  • StateManager, this is the core class of the whole architecture. It provides a consistent mechanism to manage state initializations and coroutine scopes.

The 6 files you mentioned:
Events.kt
KMPViewModel.kt
StateManager.kt
StateProviders.kt
StateReducers.kt
Repository.kt

stay the same for each app. There is not really anything to maintain.

What you personalize in the shared code of each app, is just:

  • the 4 files (Events, State, StateProvider, StateReducers) in each screen folder in the ViewModel
  • the functions, objects and sources in the DataLayer

Feel free to provide more specific feedback on which further simplifications you think could be made.

app_structure

@jiqimaogou
Copy link
Author

jiqimaogou commented Apr 14, 2021

ok, thank you. I think the answer is ok.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants