https://github.com/rainxh11/rxt
.NET Reactive Types that provide similar functionalities inspired from: (reactive, ref & computed) found in Vue.js
https://github.com/rainxh11/rxt
computed iobservable observable reactive reactive-extensions reactive-object reactive-programming
Last synced: 9 months ago
JSON representation
.NET Reactive Types that provide similar functionalities inspired from: (reactive, ref & computed) found in Vue.js
- Host: GitHub
- URL: https://github.com/rainxh11/rxt
- Owner: rainxh11
- License: mit
- Created: 2022-09-06T12:45:22.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-10T16:08:30.000Z (almost 4 years ago)
- Last Synced: 2025-09-16T09:00:58.889Z (9 months ago)
- Topics: computed, iobservable, observable, reactive, reactive-extensions, reactive-object, reactive-programming
- Language: C#
- Homepage:
- Size: 47.9 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

|Version|Downloads|
|-|-|
|[](https://www.nuget.org/packages/RxT/)||
# Rx\
.NET Reactive Types that provide similar functionalities inspired from: (`reactive`, `ref` & `computed`) found in **Vue.js**
### This library provides 4 types: `Reactive`, `ConcurrentReactive`, `Computed`, `Computed`
# Example Usage:
## `Reactive`
a reactive wrapper object that track changes of the underlying object it is wrapping.
1. Create a reactive object:
```csharp
using RxT;
var searchQuery = new Reactive("");
```
2. Change the state:
```csharp
searchQuery.Value = "search";
```
3. Track its state changes as an `IObservable`
```csharp
searchQuery
.Subscribe(x => Console.WriteLine($"Search Query: {x}"));
```
### There is also an additional `ConcurrentReactive` a thread-safe version of `Reactive`.
## `Computed`
a read-only reactive object that track changes of a `Reactive` object while applying a custom filter to its underlying `IObservable`
1. Create a computed object from previous `searchQuery` with 500ms debouncing filter
```csharp
using RxT;
var searchQuery = new Reactive("");
var searchQueryDebounced = searchQuery
.SpawnComputed(obs => obs.Throttle(500));
```
3. Track its state changes as an `IObservable`
```csharp
searchQueryDebounced
.Subscribe(x => Console.WriteLine($"Search Query Debounced: {x}"));
```
Both `Reactive` & `Computed` implements the `IObservable` interface
## `Computed`
same as `Computed` but with different type for `Value`
```csharp
using RxT;
var searchQuery = new Reactive("");
var searchLength = searchQuery
.SpawnComputed(
// Transform function to apply each time state changes
query => query.Length,
obs => obs.DistinctUntilChanged());
```
## Changing values of nested properties:
changing `Reactive.Value` value directly will only trigger state change if `T` is a primitive type or `string`, nested properties will not trigger any state change.
### Solution:
use `Reactive.Modify()` method
```csharp
using RxT;
var pagination = new Reactive(new Pagination()
{
Page = 1,
PageSize = 25,
SortBy = "+createdAt"
});
pagination.Modify((p, triggerChange) =>
{
p.Page = 2;
triggerChange();
});
record Pagination
{
public int Page { get; set; }
public int PageSize { get; set; }
public string SortBy { get; set; }
}
```
you can also omit `triggerChange()` and state change will be triggered automatically
```csharp
pagination.Modify(p => p.Page = 2);
```
same thing can be done to `Computed`, keep in mind it will change the source `Reactive.Value` as it is passed by reference
```csharp
paginationComputed = pagination.SpawnComputed(obs => obs)
paginationComputed.ModifySource(p => p.Page = 2);
```