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

KSP: use KSP to generate ViewModel boilerplate code #32

Merged
merged 12 commits into from
Jul 24, 2023
Merged

Conversation

kaushikgopal
Copy link
Owner

@kaushikgopal kaushikgopal commented Jun 27, 2023

This PR aims to use KSP to generate the boilerplate code needed for the FeatureVM class. The way the UDF model works here is that you just write the code for the FeatureVMImpl with the event → result → state/effect transformations and KSP takes care of the rest.

  • UsfViewModelProcessor has the interesting code and implements SymbolProcessor that processes all objects annotated with @UsfViewModel
  • In order to register this you need to provide a SymbolProcessorProvider file and register it in your MANIFEST/services directory
  • The goal is to have MSMovieVM generated automatically from MSMovieVMImpl by just annotating MSMovieVMImpl with @UsfViewModel

Many thanks to @CubanAzcuy for help with this 🙏🏽

@kaushikgopal kaushikgopal merged commit 49a8774 into master Jul 24, 2023
app: MSApp,
movieRepo: MSMovieRepository,
coroutineScope: CoroutineScope? = null,
) : AndroidViewModel(app), UsfVm<MSMovieEvent, MSMovieResult, MSMovieViewState, MSMovieViewEffect> {
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored generated ViewModel: no longer implements UsfVm interface, simplifying KSP logic. This change is transparent from an API user perspective. Future modifications may bring KSP generation code closer to this approach.

@CubanAzcuy was not comfortable with some of the hard-coding that was required in the ksp gen code, to enable the implementation of the interface.

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

Successfully merging this pull request may close these issues.

2 participants