Skip to content

Commit

Permalink
Add AsObservable
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Aug 5, 2024
1 parent e1c2739 commit d682d7f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions src/R3/BindableReactiveProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface IReadOnlyBindableReactiveProperty<T> : IReadOnlyBindableReactiv
IReadOnlyBindableReactiveProperty<T> EnableValidation(Func<T, Exception?> validator);
IReadOnlyBindableReactiveProperty<T> EnableValidation<TClass>([CallerMemberName] string? propertyName = null!);
IReadOnlyBindableReactiveProperty<T> EnableValidation(Expression<Func<IReadOnlyBindableReactiveProperty<T>?>> selfSelector);
Observable<T> AsObservable();
}

public interface IBindableReactiveProperty : IReadOnlyBindableReactiveProperty
Expand Down Expand Up @@ -317,6 +318,11 @@ IReadOnlyBindableReactiveProperty<T> IReadOnlyBindableReactiveProperty<T>.Enable
enableNotifyError = true;
return this;
}

public Observable<T> AsObservable()
{
return this;
}
}

internal sealed class PropertyValidationContext(ValidationContext context, ValidationAttribute[] attributes)
Expand Down
12 changes: 9 additions & 3 deletions src/R3/ReactivePropertyExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
namespace R3;
using System.Collections;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;

namespace R3;

public static class ReactivePropertyExtensions
{
Expand Down Expand Up @@ -30,12 +35,12 @@ public static BindableReactiveProperty<T> ToBindableReactiveProperty<T>(this Obs
return new BindableReactiveProperty<T>(source, initialValue, equalityComparer);
}

public static IBindableReactiveProperty<T> ToReadOnlyBindableReactiveProperty<T>(this Observable<T> source, T initialValue = default!)
public static IReadOnlyBindableReactiveProperty<T> ToReadOnlyBindableReactiveProperty<T>(this Observable<T> source, T initialValue = default!)
{
return new BindableReactiveProperty<T>(source, initialValue, EqualityComparer<T>.Default);
}

public static IBindableReactiveProperty<T> ToReadOnlyBindableReactiveProperty<T>(this Observable<T> source, IEqualityComparer<T>? equalityComparer, T initialValue = default!)
public static IReadOnlyBindableReactiveProperty<T> ToReadOnlyBindableReactiveProperty<T>(this Observable<T> source, IEqualityComparer<T>? equalityComparer, T initialValue = default!)
{
return new BindableReactiveProperty<T>(source, initialValue, equalityComparer);
}
Expand Down Expand Up @@ -74,3 +79,4 @@ protected override void OnCompletedCore(Result result)
}
}
}

0 comments on commit d682d7f

Please sign in to comment.