https://github.com/anwarpro/mvvmate
https://github.com/anwarpro/mvvmate
cmp compose-multiplatform mvvm state-management
Last synced: about 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/anwarpro/mvvmate
- Owner: anwarpro
- Created: 2024-10-05T09:44:19.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-12-12T06:33:08.000Z (3 months ago)
- Last Synced: 2025-12-13T15:38:11.484Z (3 months ago)
- Topics: cmp, compose-multiplatform, mvvm, state-management
- Language: Kotlin
- Homepage: https://helloanwar.com/mvvmate/
- Size: 527 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MVVMate
MVVMate is a minimal state management library for Compose Multiplatform, based on the MVVM
architecture.
[](https://central.sonatype.com/artifact/com.helloanwar.mvvmate/core)
[](https://anwarpro.github.io/mvvmate)
## Overview
This library provides base classes and interfaces for managing UI state, handling user actions, and
emitting side effects in a Compose Multiplatform project.
### Key Components
- **BaseViewModel**: A base ViewModel class that manages state and handles user actions.
- **BaseViewModelWithEffect**: Extends `BaseViewModel` to also manage UI side effects.
- **UiState**: A marker interface for defining UI states.
- **UiAction**: A marker interface for user actions.
- **UiEffect**: A marker interface for UI side effects.
## Installation
To use MVVMate in your project, add the following to your `build.gradle.kts`:
### For Kotlin Multiplatform Projects:
```kotlin
kotlin {
sourceSets {
val commonMain by getting {
dependencies {
implementation("com.helloanwar.mvvmate.core:1.0.0")
}
}
}
}
```
### For Android Projects:
```kotlin
dependencies {
implementation("com.helloanwar.mvvmate.core:1.0.0")
}
```
## Usage
Here's a simple example of how you can use `MVVMate` in your Compose Multiplatform project:
```kotlin
// Define your UI State
data class MyUiState(val message: String = "") : UiState
// Define your User Actions
sealed class MyUiAction : UiAction {
object ShowMessage : MyUiAction()
}
// Define your ViewModel
class MyViewModel : BaseViewModel(MyUiState()) {
override suspend fun onAction(action: MyUiAction) {
when (action) {
MyUiAction.ShowMessage -> updateState { copy(message = "Hello, World!") }
}
}
}
// Use the ViewModel in your Composable function
@Composable
fun MyScreen(viewModel: MyViewModel) {
val state by viewModel.state.collectAsState()
Text(text = state.message)
Button(onClick = { viewModel.handleAction(MyUiAction.ShowMessage) }) {
Text("Show Message")
}
}
```
## API Documentation
For more detailed information, you can check
the [API documentation](https://anwarpro.github.io/mvvmate) generated by Dokka.