Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jakdor/CrossPlatformLiveData
Android LiveData inspired .NET implementation - lifecycle aware rx streams
https://github.com/jakdor/CrossPlatformLiveData
Last synced: 3 months ago
JSON representation
Android LiveData inspired .NET implementation - lifecycle aware rx streams
- Host: GitHub
- URL: https://github.com/jakdor/CrossPlatformLiveData
- Owner: jakdor
- License: apache-2.0
- Created: 2019-08-30T11:14:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2020-05-22T10:25:49.000Z (almost 5 years ago)
- Last Synced: 2024-11-01T04:35:45.014Z (4 months ago)
- Language: C#
- Homepage: https://medium.com/@jakdor00/crossplatformlivedata-xamarin-lightweight-mvvm-library-280ab2857bec
- Size: 435 KB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-xamarin - CrossPlatformLiveData - Android LiveData inspired .NET implementation - lifecycle aware rx streams. (Reactive)
README
# CrossPlatformLiveData
### Android LiveData inspired .NET implementation - lifecycle aware rx streams[](https://travis-ci.com/jakdor/CrossPlatformLiveData)
[](https://www.nuget.org/packages/CrossPlatformLiveData/)[Medium article about CrossPlatformLiveData](https://medium.com/@jakdor00/crossplatformlivedata-xamarin-lightweight-mvvm-library-280ab2857bec)
CrossPlatformLiveData is a C# library inspired by Android Jetpack LiveData, intended for platform independent use with Xamarin and other cross platform frameworks.
CrossPlatformLiveData is a light weight solution to effective implementation of MVVM architecture pattern.
Features:
* Rx stream with UI lifecycle awareness,
* Last value cache - state preservation,
* Everything that you need to implement MVVM pattern
Installation
------- [](https://www.nuget.org/packages/CrossPlatformLiveData/) Core/Logic project - add [CrossPlatformLiveData](https://www.nuget.org/packages/CrossPlatformLiveData/) nuget,
- [](https://www.nuget.org/packages/CrossPlatformLiveData.Android/) Android project - add [CrossPlatformLiveData](https://www.nuget.org/packages/CrossPlatformLiveData/), [CrossPlatformLiveData.Android](https://www.nuget.org/packages/CrossPlatformLiveData.Android/) nuggets,
- [](https://www.nuget.org/packages/CrossPlatformLiveData.iOS/) iOS project - add [CrossPlatformLiveData](https://www.nuget.org/packages/CrossPlatformLiveData/), [CrossPlatformLiveData.iOS](https://www.nuget.org/packages/CrossPlatformLiveData.iOS/) nuggets[CrossPlatformLiveData.Android](https://www.nuget.org/packages/CrossPlatformLiveData.Android/) provides base UI classes with LifecycleManger linked to lifecycle events:\
**LiveDataActivity, LiveDataAppCompatActivity, LiveDataAppCompatDialogFragment, LiveDataFragment, LiveDataFragmentActivity, LiveDataSupportDialogFragment, LiveDataSupportFragment**[CrossPlatformLiveData.iOS](https://www.nuget.org/packages/CrossPlatformLiveData.iOS/) provides base UI classes with LifecycleManger linked to lifecycle events:\
**LiveDataViewController**For other platforms all you need to do is provide LifecycleManger with lifecyle events when they occur, implementation should be self explanatory.
Usage
------**Logic/Core:**
Add LiveData fields in ViewModel/Presenter class:
```cs
public ILiveData SampleLiveData { get; } = new LiveData();
```Post new value to LiveData:
```cs
SampleLiveData.PostValue("Hello World!");
```**UI:**
Observe LiveData streams with LifecycleManager
```cs
viewModel.SampleLiveData.Observe(LifecycleManager, OnNextSample, e => {//handle error here}));
``````cs
private void OnNextSample(string newText)
{
someTextView.Text = newText;
}
```RxWrapper (Optional)
------Optionally you can use RxWrapper template class that reduces boilerplate code by bundling value, request status, and exception in single model:
```cs
public ILiveData> NetworkingLiveData { get; } = new LiveData>();
``````cs
//Notify UI that request is pending
NetworkingLiveData.PostValue(RxWrapper.Pending());
//Data fetch has succeded
NetworkingLiveData.PostValue(RxWrapper.Ok(model1));
//Error has occured during network call
NetworkingLiveData.PostValue(RxWrapper.Error(new Exception("No network")));
``````cs
private void OnNextNetworkingData(RxWrapper response)
{
switch (response.Status)
{
case RxStatus.Ok:
//Update UI on succes
break;
case RxStatus.Pending:
//Show loading spinner
break;
case RxStatus.Error:
//Display error alert
break;
}
}
```------
[](http://tmssoft.pl/)
2020 © TMS