Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/florent37/Multiplatform-LiveData

Multiplatorm implementation of LiveDatas / MVVM in kotlin android & native ios
https://github.com/florent37/Multiplatform-LiveData

android architecture components ios kotlin livedata multiplatform mvvm native observable swift

Last synced: about 20 hours ago
JSON representation

Multiplatorm implementation of LiveDatas / MVVM in kotlin android & native ios

Awesome Lists containing this project

README

        

# Multiplatform LiveData

Réimplémentation of android LiveDatas on kotlin-multiplatform

It wraps reals livedatas on Android, and uses an Observable-Pattern on iOS

It works exactly the same as Android LiveDatas : https://developer.android.com/topic/libraries/architecture/livedata

`KLiveData` Read only observable
`KMutableLiveData` Read / Write observable
`KMediatorLiveData` Read / Write observable, capable of listen `KLiveData`

Transformations like `map` and `switchmap` are available too

```kotlin
class MainViewModel(val premiumManager: PremiumManager) {
private val _viewState = KMediatorLiveData()

val viewState = KLiveData()
get() = _viewState

init {
_viewState.value = ViewState("not premium")

_viewState.addSource(premiumManager.premium()) {
if(it) {
_viewState.value = ViewState("premium")
} else {
_viewState.value = ViewState("not premium")
}
}
}
}
```

```kotlin
class ViewState(
val userStatus: String
)
```

```kotlin
class PremiumManager {
private val premium = KMutableLiveData()
fun premium() : KLiveData {
return premium
}

fun becomePremium() {
premium.value = true
}

init {
//default value
premium.value = false
}
}
```

# Download

Add the repository
```groovy
repositories {
maven { url "https://dl.bintray.com/florent37/maven" }
}
```

## common

[ ![Download](https://api.bintray.com/packages/florent37/maven/multiplatform-livedata/images/download.svg) ](https://bintray.com/florent37/maven/multiplatform-livedata/_latestVersion)

```groovy
implementation "com.github.florent37:multiplatform-livedata:1.0.0"
```

## ios

[ ![Download](https://api.bintray.com/packages/florent37/maven/multiplatform-livedata/images/download.svg) ](https://bintray.com/florent37/maven/multiplatform-livedata/_latestVersion)

Uses a kotlin reimplementation of livedatas

```groovy
implementation "com.github.florent37:multiplatform-livedata-ios:1.0.0"
```

## android

Uses inside the jetpack's LiveDatas

[ ![Download](https://api.bintray.com/packages/florent37/maven/multiplatform-livedata/images/download.svg) ](https://bintray.com/florent37/maven/multiplatform-livedata/_latestVersion)

```groovy
implementation "com.github.florent37:multiplatform-livedata-android:1.0.0"
```

You can retrieve the real livedatas stored inside :
```
KLiveData.toLivedata : LiveData

KMutableLiveData.toMutableLiveData : MutableLiveData

KMediatorLiveData.toMediatorLivedata : MediatorLivedata
```

And create KLiveDatas from jetpacks LiveDatas

```
LiveData.toKLivedata: KLiveData

MutableLiveData.toKMutableLiveData: KMutableLiveData

MediatorLiveData.toKMediatorLivedata: KMediatorLiveData
```

## License

Copyright 2018 Florent37

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.