Git Product home page Git Product logo

multiplatform-livedata's Introduction

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<T> Read only observable KMutableLiveData<T> Read / Write observable KMediatorLiveData<T> Read / Write observable, capable of listen KLiveData

Transformations like map and switchmap are available too

class MainViewModel(val premiumManager: PremiumManager) {
    private val _viewState = KMediatorLiveData<ViewState>()
    
    val viewState = KLiveData<ViewState>()
        get() = _viewState

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

        _viewState.addSource(premiumManager.premium()) {
            if(it) {
                _viewState.value = ViewState("premium")
            } else {
                _viewState.value = ViewState("not premium")
            }
        }
    }
}
class ViewState(
    val userStatus: String
)
class PremiumManager {
    private val premium = KMutableLiveData<Boolean>()
    fun premium() : KLiveData<Boolean> {
        return premium
    }

    fun becomePremium() {
        premium.value = true
    }

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

Download

Add the repository

repositories {
    maven { url  "https://dl.bintray.com/florent37/maven" }
}

common

Download

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

ios

Download

Uses a kotlin reimplementation of livedatas

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

android

Uses inside the jetpack's LiveDatas

Download

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

You can retrieve the real livedatas stored inside :

KLiveData<T>.toLivedata : LiveData<T>

KMutableLiveData<T>.toMutableLiveData : MutableLiveData<T>

KMediatorLiveData<T>.toMediatorLivedata : MediatorLivedata<T>

And create KLiveDatas from jetpacks LiveDatas

LiveData<T>.toKLivedata: KLiveData<T>

MutableLiveData<T>.toKMutableLiveData: KMutableLiveData<T>

MediatorLiveData<T>.toKMediatorLivedata: KMediatorLiveData<T>

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.

multiplatform-livedata's People

Contributors

florent37 avatar martingagnon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

multiplatform-livedata's Issues

gradle error

After adding requerid lines to gradle and syncing my project a receive this error. Do u know how to fix it?

Could not determine the dependencies of task ':lint'.
> Could not resolve all artifacts for configuration ':releaseCompileClasspath'.
   > Could not find com.gitub.florent37:multiplatform-livedata-android:0.0.5.
     Required by:
         project :
   > Could not find com.gitub.florent37:multiplatform-livedata:0.0.5.
     Required by:
         project :

Could not resolve com.github.florent37:multiplatform-livedata-android:1.0.0.

Hi there I was trying to run the sample code, and changed version in sample/build.gradle

def liveDataVersion = "0.0.4" -> def liveDataVersion = "1.0.0"

and got this error:
ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve com.github.florent37:multiplatform-livedata-android:1.0.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.