PowRxVar 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PowRxVar --version 0.0.1
NuGet\Install-Package PowRxVar -Version 0.0.1
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PowRxVar" Version="0.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PowRxVar --version 0.0.1
#r "nuget: PowRxVar, 0.0.1"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PowRxVar as a Cake Addin
#addin nuget:?package=PowRxVar&version=0.0.1

// Install PowRxVar as a Cake Tool
#tool nuget:?package=PowRxVar&version=0.0.1

PowRxVar

Table of content

Introduction

Provides reactive variables integrated with Rx.Net:

  • implement IObservable<T> so can be queried using reactive extensions
  • can access and set the current value
  • can be combined into other variables (Combine, Switch)

Basics

// Create variables
var a = Var.Make(3);
var b = Var.Make(7);

// Get and set the value
Console.WriteLine($"{a.V}"); // 3
a.V = 4;

// Combine variables
var c = Var.Combine(a, b, (va, vb) => va * 100 + vb);
Console.WriteLine($"{c.V}"); // 407
b.V = 8;
Console.WriteLine($"{c.V}"); // 408

// Dispose a variable
a.Dispose();
var valA = a.V; // Exception
var valB = b.V; // 8
var valC = c.V; // Exception

Basic interfaces

Read only variable IRoVar<T>

interface IRoVar<out T> : IObservable<T>, IRoDispBase
{
  // IRoDispBase
  // -> can register a callback on disposal & tell if disposed
  CancellationToken CancelToken { get; }
  bool IsDisposed { get; }

  // IObservable<T>
  // -> can use it as a normal observable
  IDisposable Subscribe(IObserver<T> observer);

  // -> can read its value
  T V { get; }
}

Read write variable IRwVar<T>

interface IRwVar<T> : IRoVar<T>, IObserver<T>, IRwDispBase
{
  // IRwDispBase
  // -> inherits from IRoDispBase but can also dispose it
  CancellationTokenSource CancelSource { get; }

  // IObserver<T>
  // -> can be updated by subscribing it to an observable
  void OnNext(T value);
  void OnCompleted();
  void OnError(Exception error);

  // -> can read and write its value
  T V { get; set; }
}

Note

As IRwVar<T> inherits from IRoVar<T> you can naturally use a read write variable in place where a read only one is required.

However, if you want to prevent the calling code from casting it back to an IRwVar<T>, you can use this extension method:

static IRoBndVar<T> ToReadOnly<T>(this IRwBndVar<T> v);

This is similar to Observable.AsObservable

Bound variables

When binding variables to a UI control, it's sometimes useful to differentiate between updates done by the user through the control (inner) and updates done by the code (outer).

Usage

// Create
var v = Var.MakeBnd(7);

// Set
v.SetInner(3);
v.SetOuter(5);

// Listen to updates
v.WhenInner.Subscribe(...);
v.WhenOuter.Subscribe(...);

// Get the latest value
Console.WriteLine($"{v.V}"); // 5

Similarly to IRoVar<T> & IRwVar<T>, bound variables use IRoBndVar<T> & IRwBndVar<T>

License

MIT

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on PowRxVar:

Package Downloads
LINQPadExtras

LINQPad utility functions

PowRxVar.Maybe

Composable reactive variables

PowRxVar.WinForms

Composable reactive variables

PowLINQPad

Reactive control and utilities for LINQPad

ImdbLib

IMDB scraping

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
0.0.47 273 8/19/2023
0.0.46 186 8/9/2023
0.0.45 165 7/9/2023
0.0.44 196 7/2/2023
0.0.43 179 6/23/2023
0.0.42 175 6/23/2023
0.0.41 176 6/23/2023
0.0.40 180 6/20/2023
0.0.38 180 6/19/2023
0.0.37 186 6/17/2023
0.0.36 177 6/17/2023
0.0.35 185 6/17/2023
0.0.34 187 6/16/2023
0.0.33 175 6/13/2023
0.0.32 175 6/13/2023
0.0.31 179 6/13/2023
0.0.30 182 6/13/2023
0.0.29 187 6/13/2023
0.0.28 170 6/13/2023
0.0.27 182 6/12/2023
0.0.25 228 6/5/2023
0.0.24 189 6/5/2023
0.0.23 179 6/3/2023
0.0.22 181 6/3/2023
0.0.21 190 6/2/2023
0.0.20 191 6/2/2023
0.0.19 188 6/2/2023
0.0.18 192 6/1/2023
0.0.17 236 5/28/2023
0.0.16 235 5/28/2023
0.0.15 238 4/24/2023
0.0.14 333 1/3/2023
0.0.11 371 11/26/2022
0.0.10 345 11/24/2022
0.0.9 350 11/18/2022
0.0.8 347 11/18/2022
0.0.7 376 11/15/2022
0.0.6 396 11/15/2022
0.0.4 539 11/13/2022
0.0.1 390 8/13/2022