Rx.Net.Plus 1.1.4

Rx.Net variables library. Provide reactiveness to variables. See readme for more details

There is a newer version of this package available.
See the version list below for details.
Install-Package Rx.Net.Plus -Version 1.1.4
dotnet add package Rx.Net.Plus --version 1.1.4
<PackageReference Include="Rx.Net.Plus" Version="1.1.4" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Rx.Net.Plus --version 1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Rx.Net.Plus, 1.1.4"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Rx.Net.Plus as a Cake Addin
#addin nuget:?package=Rx.Net.Plus&version=1.1.4

// Install Rx.Net.Plus as a Cake Tool
#tool nuget:?package=Rx.Net.Plus&version=1.1.4
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Rx.Net.Plus

Bring reactiveness to variables and properties

ReactiveX gains popularity and is widely used in several platforms and languages.

If you have used Rx.Net (System.Reactive), you probably already dreamed to transform regular variable (like int, bool ) to become reactive.

What do we mean?

We would like to:

  1. React whenever variables change
  2. Connect variables to observable sources
  3. Not receive notification if same data is set again and again
  4. Continue to use these variables as before. Compare them to values, convert them...

Rx.Net.Plus introduces two new types for this purpose (+ several extension methods):

Type Purpose
RxVar replace regular variables (like int, bool...)
RxProperty to replace view-model properties (NotifyPropertyChanged pattern)

RvVar

Let start with an example:

 var isConnected = false.ToRx(); // Create a reactive variable`

Let say, connectionStatus is of type Observable

Observable connectionStatus;

we can do:

connectionStatus.Subscribe (isConnected);

or using our method:

isConnected.ListenTo (connectionStatus);

Now, RxVar's magic is to allow the following syntax:

if (isConnected != true)
{
	// Do something.
}

As well:

var anotherRxBool = true.ToRx();

if (isConnected == connectionStatus)
{
	// Do some action
}

With numeric variables (int, double...)

var intRx = 10.ToRx();               // Create a rxvar

if (intRx > 5)
{
	// React !!
}

RxVar could be used as part of state machine, and instead of polling statuses, flags, counters...

Just react upon change in this manner:

isConnected.When(true).Notify (v => reactToEvent());

RxVar implements the following interfaces:

ISubject, IConvertible, IDisposable, IComparable, IEquatable

Distinct mode

By default, RxVar propagates its data (on update) only when a new distinct value is set.

That means that if some observer is subscribed to RxVar and the same value is assigned to RxVar, it will not be published.

In order to allow every update to be propagated, RxVar provide the following method:

SetDistinctMode

Limitations

As C# does not support overloading of the assignment operator, it is impossible to assign a value directly to a variable.

Therefore the following notation is disallowed:

var number = 20.3.ToRx();
number = 10; // Not possible

Instead, RxVar provides the following syntax:

number.Value = 10;
number.Set (10);

RxProperty for WPF

Rx.Net.Plus also provides means to leverage RxVar to WPF.

The name of class to use for properties is: RxProperty and it is directly derived from RxVar.

For instance:

public class ViewModel :  IPropertyChangedProxy
{
	public RxProperty IsFunctionEnabled { get; } = false.ToRxProperty();
	public RxProperty Counter { get; }
	public RxProperty Message { get; }
}

and in XAML:

< CheckBox  IsChecked="{Binding IsFunctionEnabled}"/>
< TextBox   Text="{Binding Counter}"/>
< TextBox   Text="{Binding Message}"/>

Note that Rx.Net.Plus supports TwoWay binding mode (where target can update source as for CheckBox).

For data binding of RxProperty to work as expected, the view model shall implement a dedicated interface named IPropertyChangedProxy.

Assuming the View Model implements INotifyPropertyChanged, it shall also implements IPropertyChangedProxyas following:

void IPropertyChangedProxy.NotifyPropertyChanged(PropertyChangedEventArgs eventArgs)
{
	OnPropertyChanged (eventArgs);
}

Binding shall occur after the view is created and bound to view model.

In Caliburn framework, this occurs within the OnViewAttached method as following:

class ViewModel : Screen, IPropertyChangedProxy
{
    protected override void OnViewAttached(object view, object context)
    {
        base.OnViewAttached(view, context);
        this.BindRxPropertiesToView (view);			// Bind RxProperties to view
    }
}

In classic MVVM or other frameworks (like Prism, MVVM Light...), call to BindRxPropertiesToView can be handled in Loaded event handler.

Extension Methods

Method Description Usage
RedirectTo an alias of Subscribe rxVar.RedirectTo(rxVar2)
Notify an alias of Subscribe rxVar.Notify(rxVar2)
When equivalent of Where (value ⇒ value.Equals(v)) rxVar.When(true).Notify (rxVar2)
ToRxVar creates an instance of RxVar of the type of var var rxVar = 10.ToRxVar()
ToRxVarAndSubscribe creates an instance of RxVar of the same type of observable source and subscribe the new instance to source IObservable<int> obs; var rxvar = obs.Where(v => v > 10).ToRxVarAndSubscribe();
ToRxProperty creates an instance of RxProperty of the type of var RxProperty<int> Counter => 10.ToRxProperty();
ToRxPropertyAndSubscribe** creates an instance of RxProperty of the same type of observable source and subscribe the new instance to source RxProperty<bool> IsPresent;
BindRxPropertiesToView bind the rxproperties of the view model vm (which implements IPropertyChangedProxy) to the view. this.BindRxPropertiesToView(view)
True, False, Not pseudo attributes may be used as replacement for (var == true, var == false) isConnected.True, isConnected.False, isConnected.Not
DisposableBaseClass an abstract class to derive from to support Dispose Pattern with some extras

Contact us !

For any comment, suggestion...please leave a comment to reactivesw@outlook.com

Rx.Net.Plus

Bring reactiveness to variables and properties

ReactiveX gains popularity and is widely used in several platforms and languages.

If you have used Rx.Net (System.Reactive), you probably already dreamed to transform regular variable (like int, bool ) to become reactive.

What do we mean?

We would like to:

  1. React whenever variables change
  2. Connect variables to observable sources
  3. Not receive notification if same data is set again and again
  4. Continue to use these variables as before. Compare them to values, convert them...

Rx.Net.Plus introduces two new types for this purpose (+ several extension methods):

Type Purpose
RxVar replace regular variables (like int, bool...)
RxProperty to replace view-model properties (NotifyPropertyChanged pattern)

RvVar

Let start with an example:

 var isConnected = false.ToRx(); // Create a reactive variable`

Let say, connectionStatus is of type Observable

Observable connectionStatus;

we can do:

connectionStatus.Subscribe (isConnected);

or using our method:

isConnected.ListenTo (connectionStatus);

Now, RxVar's magic is to allow the following syntax:

if (isConnected != true)
{
	// Do something.
}

As well:

var anotherRxBool = true.ToRx();

if (isConnected == connectionStatus)
{
	// Do some action
}

With numeric variables (int, double...)

var intRx = 10.ToRx();               // Create a rxvar

if (intRx > 5)
{
	// React !!
}

RxVar could be used as part of state machine, and instead of polling statuses, flags, counters...

Just react upon change in this manner:

isConnected.When(true).Notify (v => reactToEvent());

RxVar implements the following interfaces:

ISubject, IConvertible, IDisposable, IComparable, IEquatable

Distinct mode

By default, RxVar propagates its data (on update) only when a new distinct value is set.

That means that if some observer is subscribed to RxVar and the same value is assigned to RxVar, it will not be published.

In order to allow every update to be propagated, RxVar provide the following method:

SetDistinctMode

Limitations

As C# does not support overloading of the assignment operator, it is impossible to assign a value directly to a variable.

Therefore the following notation is disallowed:

var number = 20.3.ToRx();
number = 10; // Not possible

Instead, RxVar provides the following syntax:

number.Value = 10;
number.Set (10);

RxProperty for WPF

Rx.Net.Plus also provides means to leverage RxVar to WPF.

The name of class to use for properties is: RxProperty and it is directly derived from RxVar.

For instance:

public class ViewModel :  IPropertyChangedProxy
{
	public RxProperty IsFunctionEnabled { get; } = false.ToRxProperty();
	public RxProperty Counter { get; }
	public RxProperty Message { get; }
}

and in XAML:

< CheckBox  IsChecked="{Binding IsFunctionEnabled}"/>
< TextBox   Text="{Binding Counter}"/>
< TextBox   Text="{Binding Message}"/>

Note that Rx.Net.Plus supports TwoWay binding mode (where target can update source as for CheckBox).

For data binding of RxProperty to work as expected, the view model shall implement a dedicated interface named IPropertyChangedProxy.

Assuming the View Model implements INotifyPropertyChanged, it shall also implements IPropertyChangedProxyas following:

void IPropertyChangedProxy.NotifyPropertyChanged(PropertyChangedEventArgs eventArgs)
{
	OnPropertyChanged (eventArgs);
}

Binding shall occur after the view is created and bound to view model.

In Caliburn framework, this occurs within the OnViewAttached method as following:

class ViewModel : Screen, IPropertyChangedProxy
{
    protected override void OnViewAttached(object view, object context)
    {
        base.OnViewAttached(view, context);
        this.BindRxPropertiesToView (view);			// Bind RxProperties to view
    }
}

In classic MVVM or other frameworks (like Prism, MVVM Light...), call to BindRxPropertiesToView can be handled in Loaded event handler.

Extension Methods

Method Description Usage
RedirectTo an alias of Subscribe rxVar.RedirectTo(rxVar2)
Notify an alias of Subscribe rxVar.Notify(rxVar2)
When equivalent of Where (value ⇒ value.Equals(v)) rxVar.When(true).Notify (rxVar2)
ToRxVar creates an instance of RxVar of the type of var var rxVar = 10.ToRxVar()
ToRxVarAndSubscribe creates an instance of RxVar of the same type of observable source and subscribe the new instance to source IObservable<int> obs; var rxvar = obs.Where(v => v > 10).ToRxVarAndSubscribe();
ToRxProperty creates an instance of RxProperty of the type of var RxProperty<int> Counter => 10.ToRxProperty();
ToRxPropertyAndSubscribe** creates an instance of RxProperty of the same type of observable source and subscribe the new instance to source RxProperty<bool> IsPresent;
BindRxPropertiesToView bind the rxproperties of the view model vm (which implements IPropertyChangedProxy) to the view. this.BindRxPropertiesToView(view)
True, False, Not pseudo attributes may be used as replacement for (var == true, var == false) isConnected.True, isConnected.False, isConnected.Not
DisposableBaseClass an abstract class to derive from to support Dispose Pattern with some extras

Contact us !

For any comment, suggestion...please leave a comment to reactivesw@outlook.com

Release Notes

First release

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Rx.Net.Plus:

Package Downloads
Rx.Net.Plus.Json
Extension to Rx.Net.Plus to support Json flat serialization

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.1.15 780 11/9/2020
1.1.14 120 11/5/2020
1.1.13 975 6/16/2020
1.1.12 1,438 10/10/2019
1.1.11 230 10/3/2019
1.1.10 1,152 8/1/2019
1.1.9 1,746 9/16/2018
1.1.8 1,745 9/4/2018
1.1.7 405 9/3/2018
1.1.6 408 9/2/2018
1.1.5 397 8/29/2018
1.1.4 415 8/27/2018
1.0.12 588 8/23/2018
1.0.11 376 8/23/2018
1.0.10 412 8/22/2018
1.0.9 442 8/2/2018
1.0.8 441 8/2/2018
1.0.7 410 7/30/2018
1.0.6 432 7/30/2018
1.0.5 426 7/30/2018
Show less