Dataflow mediator for LiveData
Library ID dataflow-mediator-livedata

Field to LiveData conversion

Sometimes it may also arise the need to convert a Field to a LiveData object, if some external library requires the latter class.

As for the opposite conversion, we have an extension function just for that, which is called toLiveData():

val fld : Field<String> = getField() //Obtain a Field object from somewhere val liveData : LiveData<String> = field.toLiveData() //Converts the Field to a LiveData
Field<String> fld = getField(); //Obtain a Field object from somewhere LiveData<String> liveData = DataflowLiveDataMediation.toLiveData(field) //Converts the Field to a LiveData

The returned LiveData instance will listen to the Field changes as long as it is active.

Mutable variant


Once again, the function to convert a MutableField to a MutableLiveData is pretty idomatic: toMutableLiveData().

Here's an example usage:

val mutableField : MutableField<String> = getMutableField() //Obtain a MutableField object from somewhere val mutableLiveData : MutableLiveData<String> = mutableField.toMutableLiveData() //Converts the MutableField to a MutableLiveData
MutableField<String> mutableField = getMutableField(); //Obtain a ableField object from somewhere MutableLiveData<String> mutableLiveData = DataflowLiveDataMediation.toMutableLiveData(mutableField) //Converts the MutableField to a MutableLiveData

Whenever the returned MutableLiveData value is changed, the original MutableField will be updated accordingly.