Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/florent37/Multiplatform-LiveData
- Owner: florent37
- License: apache-2.0
- Archived: true
- Created: 2018-11-08T12:56:26.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-23T10:15:26.000Z (over 4 years ago)
- Last Synced: 2024-08-02T09:26:35.474Z (3 months ago)
- Topics: android, architecture, components, ios, kotlin, livedata, multiplatform, mvvm, native, observable, swift
- Language: Kotlin
- Homepage:
- Size: 141 KB
- Stars: 94
- Watchers: 7
- Forks: 11
- Open Issues: 3
-
Metadata Files:
- Readme: ReadMe.md
- License: LICENSE
Awesome Lists containing this project
- awesome-kotlin-multiplatform - Multiplatform-LiveData - Multiplatorm implementation of LiveDatas / MVVM in kotlin android & native ios (Libraries / Reactive)
- awesome-ccamel - florent37/Multiplatform-LiveData - Multiplatorm implementation of LiveDatas / MVVM in kotlin android & native ios (Kotlin)
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() = _viewStateinit {
_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 : LiveDataKMutableLiveData.toMutableLiveData : MutableLiveData
KMediatorLiveData.toMediatorLivedata : MediatorLivedata
```And create KLiveDatas from jetpacks LiveDatas
```
LiveData.toKLivedata: KLiveDataMutableLiveData.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.