All Projects → futuredapp → arkitekt-kmm

futuredapp / arkitekt-kmm

Licence: other
KMM library for UseCase abstraction

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to arkitekt-kmm

mpp-example
This project is a minimum example of Kotlin Multiplatform Project.
Stars: ✭ 32 (-13.51%)
Mutual labels:  kotlin-multiplatform
thelema-engine
Thelema - 3D graphics engine, written in Kotlin. Based on sources of libGDX.
Stars: ✭ 51 (+37.84%)
Mutual labels:  kotlin-multiplatform
inject
A simple Kotlin multi-platform abstraction around the javax.inject annotations.
Stars: ✭ 42 (+13.51%)
Mutual labels:  kotlin-multiplatform
codeforces watcher
Mobile client application for Codeforces competitive programming platform.
Stars: ✭ 81 (+118.92%)
Mutual labels:  kotlin-multiplatform
kmm
Rick & Morty Kotlin Multiplatform Mobile: Ktor, Sqldelight, Koin, Flow, MVI, SwiftUI, Compose
Stars: ✭ 52 (+40.54%)
Mutual labels:  kotlin-multiplatform
trikot
🧶 Trikot is a framework that helps building Kotlin Multiplatform apps. iOS, Android and Web are the primary targets.
Stars: ✭ 44 (+18.92%)
Mutual labels:  kotlin-multiplatform
moko-graphics
Graphics primitives for mobile (android & ios) Kotlin Multiplatform development
Stars: ✭ 11 (-70.27%)
Mutual labels:  kotlin-multiplatform
bitcoin-kmp
Kotlin Multiplatform Bitcoin Library
Stars: ✭ 29 (-21.62%)
Mutual labels:  kotlin-multiplatform
hello-kotlin-multiplatform
Multiplatform Kotlin Hello World (Android/Java/JavaScript)
Stars: ✭ 64 (+72.97%)
Mutual labels:  kotlin-multiplatform
storyblok-mp-SDK
Storyblok Kotlin Multiplatform SDK (Android, JVM, JS, iOS, ...)
Stars: ✭ 16 (-56.76%)
Mutual labels:  kotlin-multiplatform
kotlin-everywhere
Kotlin/Everywhere Beijing 2019
Stars: ✭ 31 (-16.22%)
Mutual labels:  kotlin-multiplatform
SQLiter
Minimal multiplatform sqlite library
Stars: ✭ 120 (+224.32%)
Mutual labels:  kotlin-multiplatform
2p-kt
A Kotlin Multi-Platform ecosystem for symbolic AI
Stars: ✭ 52 (+40.54%)
Mutual labels:  kotlin-multiplatform
Penicillin
Modern powerful Twitter API wrapper for Kotlin Multiplatform. #PureKotlin
Stars: ✭ 91 (+145.95%)
Mutual labels:  kotlin-multiplatform
SevenFacette
7Facette is an open-source multiplatform test automation library supporting JVM and JS.
Stars: ✭ 28 (-24.32%)
Mutual labels:  kotlin-multiplatform
trikot.http
HTTP networking abstraction for Kotlin Multiplatform
Stars: ✭ 15 (-59.46%)
Mutual labels:  kotlin-multiplatform
kotlin-multiplatform-example
A barebones Kotlin multiplatform project with JVM and JS targets
Stars: ✭ 15 (-59.46%)
Mutual labels:  kotlin-multiplatform
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (+0%)
Mutual labels:  kotlin-multiplatform
GitHubKotlinMPPSample
No description or website provided.
Stars: ✭ 15 (-59.46%)
Mutual labels:  kotlin-multiplatform
ToDometer Multiplatform
WIP Kotlin Multiplatform project: A meter to-do list built with Android Jetpack, Compose UI Multiplatform, Wear Compose, SQLDelight, Koin Multiplatform, SwiftUI, Ktor Server / Client, Exposed...
Stars: ✭ 145 (+291.89%)
Mutual labels:  kotlin-multiplatform

Arkitekt kmm

Km-usecases

Is a Kotlin multiplatform mobile library that helps you with abstraction of Usecase as a component from clean architecture. Its main objective is separation of concerns and better domain modeling. It is backed by Kotlinx Coroutines

Benefits

  • delegate work to background thread
  • cancel on reexecution (optional)
  • error handling
  • auto-cancel of coroutine context

Usage

Library contains two main parts UseCase and FlowUseCase.

  • UseCase is for events that return single response. (e.g. REST API call GET, POST...)
  • FlowUseCase is for events that return multiple responses. (e.g. Location data updates...)

UseCase

UseCase same as FlowUseCase has two generic parameters. The first is argument type, the second specify return type. If you don't need any of these, just put Unit in there. When creating a usecase, don't forget to freeze() it in init block, but after local parameters initialization. If you use DI, inject before freezing, or you will end up with InvalidMutabilityException. This step won't be necessary after release of New Native Memory Model. You can preview it with Kotlin 1.6.0-M1.

Define a usecase in common module

// Common
class GetCoinsListUseCase : UseCase<Unit, List<Coin>>() {
    private val coinStore: CoinStore = CoinStore(RestApiManager, DatabaseManager)

    init {
        freeze()
    }

    override suspend fun build(arg: Unit): List<Coin> {
        return coinStore.fetchCoins().coins.map {
            Coin(
                it.id,
                it.name,
                it.icon,
                it.symbol,
                it.price
            )
        }
    }
}

Consume the Usecase from Android.

You can execute the Usecase anywhere you want, but you have to implement the CoroutineScopeOwner interface and specify the coroutineContext where the Usecase will be executed. So the ViewModel is the most common option.

// Android
class CoinsViewModel : ViewModel(), CoroutineScopeOwner {

      override val coroutineScope: CoroutineScope
          get() = viewModelScope
        
      private val getCoinsUseCase = GetCoinsListUseCase()
      var coins by mutableStateOf(emptyList<Coin>())

      fun fetchCoins() {
          getCoinsUseCase.execute(Unit) {
              onSuccess { coins = it.list }
              onError { print(it.message) }
          }
      }
}

Consume the Usecase from iOS.

As the Swift language also features closing lambdas, you can execute the Usecase nearly in the same fashion as on Android.

// iOS
class CoinsViewModel : BaseViewModel, ObservableObject {
    @Published var coins = [Coin]()

    private let getCoinsUseCase = GetCoinsListUseCase()

    func getCoins() {
        getCoinsUseCase.execute(self, args: KotlinUnit()) {
            $0.onNext { list in
                guard let coinsList = list?.list else { return }
                self.coins = coinsList as [Coin]
            }
            $0.onError { error in
                print(error)
            }
        }
    }
}

Example

Check out the full example in my other project the KMM Template

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].