Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ekeitho/uni
Unidirectional "Flow" architecture
https://github.com/ekeitho/uni
Last synced: about 2 months ago
JSON representation
Unidirectional "Flow" architecture
- Host: GitHub
- URL: https://github.com/ekeitho/uni
- Owner: ekeitho
- Created: 2022-03-04T04:37:24.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-12-20T00:28:06.000Z (about 2 years ago)
- Last Synced: 2024-03-16T10:35:02.724Z (10 months ago)
- Language: Kotlin
- Size: 130 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
![uni github actions](https://github.com/ekeitho/uni/actions/workflows/android.yml/badge.svg)
# uni
Unidirectional "Flow" architecture. Main intention of usage is for Android.An example usage
```kotlindata class Wiki(private val wikiService: WikiService) {
data class State(val wikiResponse: WikiResponse? = null)
sealed class Action {
object FetchRandomWikiAction : Action()
data class WikiResponseAction(val wikiResponse: WikiResponse) : Action()
}
fun getViewModel() =
uniViewModelDSL(State()) {
effect { flow ->
flow
.filterIsInstance()
.flatMapLatest {
wikiService.getRandomWiki().map { Action.WikiResponseAction(it) }
}
}reducer { action, state ->
when (action) {
is Action.WikiResponseAction -> state.copy(wikiResponse = action.wikiResponse)
is Action.FetchRandomWikiAction -> state.copy(wikiResponse = null)
}
}
}
}
```Then in Compose, using whichever DI framework, in this case using Koins `getViewModel` we can do...
```kotlin
setContent {
val vm = getViewModel>()
val state by vm.liveDataState.observeAsState(initial = Wiki.State())WikiScreen(
wikiResponse = state?.wikiResponse,
onButtonTap = {
vm.dispatch(Wiki.Action.FetchRandomWikiAction)
}
)
}
```[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.ekeitho.uni/uni/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.ekeitho.uni/uni)
To use in your project:
```
implementation "com.ekeitho.uni:uni:$latest-version"
```