Stage 3 changes - Xantier/multiplat-workshop GitHub Wiki

Starting to extract common business logic

New module - multiplat-workshop-client

  • build.gradle
apply plugin: 'kotlin-platform-common'
apply plugin: 'kotlinx-serialization'

dependencies {
    compile project(":multiplat-workshop-common")
}
  • PhotoProvider.kt
class PhotoProvider {
    fun fetchPhotos(clientProvider: ApiClientProvider) {
        val client = clientProvider.getApiClient()
        val photos = client.fetchPhotos()
        println(JSON.nonstrict.parse(photoListSerializer, photos))
    }
}
  • CommonApiClientProvider.kt
expect class ApiClientProvider {
    fun getApiClient() : ApiClient
}

New Module - multiplatform-client-react

  • build.gradle

    • Move gradle.build from multiplat-workshop-js
    • Modify expectedBy to point to multiplat-workshop-client
    • Add dependency to multiplat-workshop-js
  • Implement ApiClientProvider

  • Move index.kt && index.html files from multiplat-workshop-js module - leave only ApiClient

    • Modify index.kt to create PhotoProvider and call fetchPhotos with an instance of JS ApiClient

New Module - multiplatform-client-desktop

  • build.gradle
apply plugin: 'kotlin-platform-jvm'

dependencies {
    expectedBy project(":multiplat-workshop-client")
    compile project(":multiplat-workshop-jvm")
}

compileKotlin {
    kotlinOptions.jvmTarget = "1.8"
}
  • Modify expectedBy to point to multiplat-workshop-client

  • Add dependency to multiplat-workshop-jvm

  • Implement ApiClientProvider

  • Move Main.kt file from multiplat-workshop-jvm module - leave only ApiClient

    • Modify Main.kt to create PhotoProvider and call fetchPhotos with an instance of JS ApiClient

JVM

  • gradle.build
    • Modify file, remove kotlin stdlib, it's not needed
  • Module should contain only ApiClient implementation and okhttp dependency

JS

  • gradle.build
    • Remove everything apart from coroutines, serialization, expectedBy and platform plugin