Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Marplex/LiveData
A simple android LiveData alternative for WPF and C#
https://github.com/Marplex/LiveData
dotnet mvvm reactiveui wpf wpf-application wpf-ui
Last synced: 2 months ago
JSON representation
A simple android LiveData alternative for WPF and C#
- Host: GitHub
- URL: https://github.com/Marplex/LiveData
- Owner: Marplex
- License: mit
- Created: 2022-04-13T18:18:31.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-04-23T12:13:11.000Z (over 2 years ago)
- Last Synced: 2024-10-10T22:21:03.679Z (2 months ago)
- Topics: dotnet, mvvm, reactiveui, wpf, wpf-application, wpf-ui
- Language: C#
- Homepage: https://marplex.medium.com/how-i-build-wpf-apps-in-the-android-way-a9bad5e985f9
- Size: 61.5 KB
- Stars: 14
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
![](./Art/cover.png)
LiveData
A simple android LiveData alternative for WPF and C#
Easily add reactive properties with a single line of code
# Features
- [x] Automatically notifies value changes
- [x] Add reactive properties in one line
- [x] Map LiveData values (Map)
- [x] Convert one LiveData to another (SwitchMap)
- [x] Combine two LiveData
- [x] Debounce emitted values
- [x] Delay emitted values
- [x] Convert `Task` to LiveData# Available for
![NET6](https://img.shields.io/badge/.NET-6.0-red)
![NET5](https://img.shields.io/badge/.NET-5.0-blue)
![NETCore3](https://img.shields.io/badge/.NET%20Core-3.1-brightgreen)
![NETFramework48](https://img.shields.io/badge/.NET%20Framework-4.8-orange)
![NETFramework47](https://img.shields.io/badge/.NET%20Framework-4.7-orange)
![NETFramework46](https://img.shields.io/badge/.NET%20Framework-4.6-orange)# How to use
Use LiveData on your viewmodels and add reactive properties
```c#
public class MyViewModel : ViewModel {public LiveData SearchQuery { get; set; }
public LiveData IsVisible { get; set; }public MyViewModel() {
SearchQuery = new LiveData("");
SearchQuery.Value = "myname";//React to SearchQuery changes and map the value to a boolean.
//Everything is automatically notified to the UI
IsVisible = SearchQuery.Map(it => it != "");
}}
```## Transformations
```c#
//Map values to async functions
IsVisible = SearchQuery.MapAsync(it => Task.FromResult(true));//Delay emitted values
DelayedLiveData = MyLiveData.Delay(1000);//Debounce emitted values
Debounced = MyLiveData.Debounce(1000);//Combine two LiveData
Combined = First.CombineWith(Second, (a, b) => a + b);//Convert one LiveData to another LiveData
Mapped = IsVisible.SwitchMap(it => it ? SearchResultLiveData : EmptyResultLiveData);//Concatenate transformation functions
FinalLiveData = Name.Delay(1000)
.Debounce(800)
.Map(name => "Hello" + name);
```## Utils
Extensions further simplify using and transforming LiveData objects.
```c#
//Convert task to LiveData
var task = Task.FromResult(true);
LiveData IsVisible = task.ToLiveData();//Append, prepend, remove into LiveData of lists
//Changes are notified
LiveData> Items;
Items.Remove("first");
Items.Append("first");
Items.Prepend("first");
```## LiveData and XAML Binding
Bind LiveData to xaml properties
```xml
```
## 📜 License
```xml
Copyright (c) 2022 MarcoPermission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
```