Skip to content

Commit

Permalink
Merge pull request #227 from runceel/main
Browse files Browse the repository at this point in the history
v7.7
  • Loading branch information
runceel authored Jan 26, 2021
2 parents 2340d86 + d6377b2 commit bd5292a
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 3 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ It's very simple.

ReactiveProperty doesn't provide base class by ViewModel, which means that ReactiveProperty can be used together with another MVVM library like Prism, MVVMLight, etc...

## Help support ReactiveProperty

|Name|GitHub Sponsors|
|----|----|
|runceel|https://github.com/sponsors/runceel|

## Documentation

[ReactiveProperty documentation](https://runceel.github.io/ReactiveProperty/)
Expand Down
5 changes: 5 additions & 0 deletions Source/ReactiveProperty.Core/ReactivePropertyMode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public enum ReactivePropertyMode
/// </summary>
IgnoreInitialValidationError = 0x04,

/// <summary>
/// Ignore exception
/// </summary>
IgnoreException = 0x08,

/// <summary>
/// Default mode value. It is same as DistinctUntilChanged | RaiseLatestValueOnSubscribe.
/// </summary>
Expand Down
6 changes: 5 additions & 1 deletion Source/ReactiveProperty.Core/ReactivePropertySlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.ExceptionServices;
using System.Threading;
using Reactive.Bindings.Internals;

Expand Down Expand Up @@ -295,6 +296,8 @@ public T Value

private bool IsRaiseLatestValueOnSubscribe => (_mode & ReactivePropertyMode.RaiseLatestValueOnSubscribe) == ReactivePropertyMode.RaiseLatestValueOnSubscribe;

private bool IsIgnoreException => (_mode & ReactivePropertyMode.IgnoreException) == ReactivePropertyMode.IgnoreException;

/// <summary>
/// Initializes a new instance of the <see cref="ReadOnlyReactivePropertySlim{T}"/> class.
/// </summary>
Expand Down Expand Up @@ -427,7 +430,8 @@ void IObserver<T>.OnNext(T value)

void IObserver<T>.OnError(Exception error)
{
// do nothing.
if (IsIgnoreException) return;
ExceptionDispatchInfo.Capture(error).Throw();
}

void IObserver<T>.OnCompleted()
Expand Down
10 changes: 9 additions & 1 deletion Source/ReactiveProperty.NETStandard/ReadOnlyReactiveProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using System.ComponentModel;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.PlatformServices;
using System.Runtime.ExceptionServices;
using Reactive.Bindings.Internals;

namespace Reactive.Bindings
Expand Down Expand Up @@ -31,6 +33,7 @@ public class ReadOnlyReactiveProperty<T> : IReadOnlyReactiveProperty<T>, IObserv

private bool IsRaiseLatestValueOnSubscribe => (_mode & ReactivePropertyMode.RaiseLatestValueOnSubscribe) == ReactivePropertyMode.RaiseLatestValueOnSubscribe;
private bool IsDistinctUntilChanged => (_mode & ReactivePropertyMode.DistinctUntilChanged) == ReactivePropertyMode.DistinctUntilChanged;
private bool IsIgnoreException => (_mode & ReactivePropertyMode.IgnoreException) == ReactivePropertyMode.IgnoreException;

/// <summary>
/// Initializes a new instance of the <see cref="ReadOnlyReactiveProperty{T}"/> class.
Expand Down Expand Up @@ -66,6 +69,10 @@ public ReadOnlyReactiveProperty(

object IReadOnlyReactiveProperty.Value => Value;

/// <summary>
/// Gets a value indicating whether this instance is disposed.
/// </summary>
/// <value><c>true</c> if this instance is disposed; otherwise, <c>false</c>.</value>
public bool IsDisposed => (int)_mode == IsDisposedFlagNumber;

/// <summary>
Expand Down Expand Up @@ -181,7 +188,8 @@ void IObserver<T>.OnNext(T value)

void IObserver<T>.OnError(Exception error)
{
// do nothing.
if (IsIgnoreException) return;
ExceptionDispatchInfo.Capture(error).Throw();
}

void IObserver<T>.OnCompleted()
Expand Down
2 changes: 1 addition & 1 deletion Source/SharedProperties.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<RootNamespace>Reactive.Bindings</RootNamespace>
<Version>7.6.1</Version>
<Version>7.7.0</Version>
<Authors>neuecc xin9le okazuki</Authors>
<PackageProjectUrl>https://github.com/runceel/ReactiveProperty</PackageProjectUrl>
<PackageTags>rx mvvm async rx-main reactive</PackageTags>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
Expand Down Expand Up @@ -199,5 +200,24 @@ public void CreateFromObservableThatCompleteImmediately()
var x = Observable.Return(1).ToReadOnlyReactivePropertySlim();
x.Value.Is(1);
}

[TestMethod]
public void ExceptionThrowsInConvertionLogic()
{
Assert.ThrowsException<Exception>(() =>
_ = Observable.Return(Unit.Default)
.Do(_ => throw new Exception("test"))
.ToReadOnlyReactivePropertySlim(),
"test");
}

[TestMethod]
public void ExceptionThrowsInConvertionLogicWithIgnoreExceptionFlag()
{
AssertEx.DoesNotThrow(() =>
_ = Observable.Return(Unit.Default)
.Do(_ => throw new Exception("test"))
.ToReadOnlyReactivePropertySlim(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreException));
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
Expand Down Expand Up @@ -190,5 +191,25 @@ public void CreateFromCompletedObservableTest()
recorder.Messages.Count.Is(1);
recorder.Messages.Is(OnCompleted<string>(0));
}

[TestMethod]
public void ExceptionThrowsInConvertionLogic()
{
Assert.ThrowsException<Exception>(() =>
_ = Observable.Return(Unit.Default)
.Do(_ => throw new Exception("test"))
.ToReadOnlyReactiveProperty(),
"test");
}

[TestMethod]
public void ExceptionThrowsInConvertionLogicWithIgnoreExceptionFlag()
{
AssertEx.DoesNotThrow(() =>
_ = Observable.Return(Unit.Default)
.Do(_ => throw new Exception("test"))
.ToReadOnlyReactiveProperty(mode: ReactivePropertyMode.Default | ReactivePropertyMode.IgnoreException));
}

}
}

0 comments on commit bd5292a

Please sign in to comment.