https://github.com/sunnydaydev/arch-mvi
Kotlin MVI framework
https://github.com/sunnydaydev/arch-mvi
Last synced: 9 months ago
JSON representation
Kotlin MVI framework
- Host: GitHub
- URL: https://github.com/sunnydaydev/arch-mvi
- Owner: SunnyDayDev
- License: mit
- Created: 2023-03-14T11:22:55.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-06-13T03:58:28.000Z (about 3 years ago)
- Last Synced: 2024-12-28T05:41:46.135Z (over 1 year ago)
- Language: Kotlin
- Size: 188 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
[](https://ci.sunnyday.dev/buildConfiguration/ArchMvi_Test/lastFinished?branch=%3Cdefault%3E)
[](https://ci.sunnyday.dev/buildConfiguration/ArchMvi_Test/lastFinished?buildTab=tests&branch=%3Cdefault%3E)
[](https://github.com/users/SunnyDayDev/projects/2/views/3)
[](https://jitpack.io/#dev.sunnyday/arch-mvi)
# arch-mvi
Kotlin MVI framework
# Status
In progress. README is lean and will be updated later.
# Integration
```kotlin
// build.gradle.kts
implementation("dev.sunnyday.arch-mvi:mvi-core:$version")
implementation("dev.sunnyday.arch-mvi:mvi-kit-coroutine:$version")
```
```kotlin
// Somewhere in the code
import dev.sunnyday.arch.mvi.coroutine.setupFactories
import dev.sunnyday.arch.mvi.MviKit
fun initMvi() {
MviKit.setupFactories()
}
```
# Usage
```kotlin
fun startFeature(featureCoroutineScope: CoroutineScope): MviFeature {
// null can be skipped, just showed that they are
val starter = MviKit.withParentCoroutine(featureCoroutineScope)
.createFeatureStarter(
initialStateProvider = { State("initial") },
initialEventsProvider = null,
initialInputEventsProvider = null,
initialSideEffectsProvider = null,
stateMachineInstanceFactory = { // this: StateMachineInstanceFactory.FactoryScope -> // with createStateMachine method
createStateMachine(
reducer = FeatureReducer(),
stateTransitionListener = null,
)
},
featureInstanceFactory = { // this: FeatureInstanceFactory.FactoryScope -> // with createFeature method
createFeature(
eventHandler = FeatureInputEventHandler(),
sideEffectHandler = FeatureSideEffectHandler(),
onReadyCallback = null,
)
}
)
return starter.start()
}
// Or minimal, even without EventHandler
fun startFeature(): MviFeature {
val starter = MviKit.createFeatureStarter(
initialStateProvider = { State("initial") },
stateMachineInstanceFactory = {
createStateMachine(
reducer = FeatureReducer(),
)
},
featureInstanceFactory = {
createFeature(
sideEffectHandler = FeatureSideEffectHandler(),
)
}
)
return starter.start()
}
```
A state machine or feature can be instantiated independently using own MviKit's factory method.