| Version | Downloads |
|---|---|
.NET Reactive Types that provide similar functionalities inspired from: (reactive, ref & computed) found in Vue.js
a reactive wrapper object that track changes of the underlying object it is wrapping.
- Create a reactive object:
using RxT;
var searchQuery = new Reactive<string>("");- Change the state:
searchQuery.Value = "search";- Track its state changes as an
IObservable<T>
searchQuery
.Subscribe(x => Console.WriteLine($"Search Query: {x}"));a read-only reactive object that track changes of a Reactive<T> object while applying a custom filter to its underlying IObservable<T>
- Create a computed object from previous
searchQuerywith 500ms debouncing filter
using RxT;
var searchQuery = new Reactive<string>("");
var searchQueryDebounced = searchQuery
.SpawnComputed(obs => obs.Throttle(500));- Track its state changes as an
IObservable<T>
searchQueryDebounced
.Subscribe(x => Console.WriteLine($"Search Query Debounced: {x}"));Both Reactive<T> & Computed<T> implements the IObservable<T> interface
same as Computed<T> but with different type for Value
using RxT;
var searchQuery = new Reactive<string>("");
var searchLength = searchQuery
.SpawnComputed(
// Transform function to apply each time state changes
query => query.Length,
obs => obs.DistinctUntilChanged());changing Reactive<T>.Value value directly will only trigger state change if T is a primitive type or string, nested properties will not trigger any state change.
use Reactive<T>.Modify() method
using RxT;
var pagination = new Reactive<Pagination>(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
pagination.Modify(p => p.Page = 2);same thing can be done to Computed<T>, keep in mind it will change the source Reactive<T>.Value as it is passed by reference
paginationComputed = pagination.SpawnComputed(obs => obs)
paginationComputed.ModifySource(p => p.Page = 2);