Skip to content

Commit

Permalink
Merge pull request #433 from runceel/main
Browse files Browse the repository at this point in the history
Release v9.3.0
  • Loading branch information
runceel authored Jul 31, 2023
2 parents e9a5ffc + bc45dd9 commit a9cb8ff
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,16 @@ ViewModel's implementation using ReactiveProperty:
```cs
public class AViewModel
{
public ReactivePropertySlim<string> Name { get; }
public ReactivePropertySlim<string> Memo { get; }
public ValidatableReactiveProperty<string> Name { get; }
public ValidatableReactiveProperty<string> Memo { get; }
public ReactiveCommandSlim DoSomethingCommand { get; }

public AViewModel()
{
Name = new ReactiveProperty<string>()
.SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
Memo = new ReactiveProperty<string>()
.SetValidateNotifyError(x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
Name = new ValidatableReactiveProperty<string>("",
x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
Memo = new ValidatableReactiveProperty<string>("",
x => string.IsNullOrEmpty(x) ? "Invalid value" : null);
DoSomethingCommand = new[]
{
Name.ObserveHasErrors,
Expand Down
2 changes: 1 addition & 1 deletion Source/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>
<PropertyGroup>
<RootNamespace>Reactive.Bindings</RootNamespace>
<Version>9.2.0</Version>
<Version>9.3.0</Version>
<Authors>neuecc xin9le okazuki</Authors>
<PackageProjectUrl>https://github.com/runceel/ReactiveProperty</PackageProjectUrl>
<PackageTags>rx mvvm async rx-main reactive</PackageTags>
Expand Down
37 changes: 19 additions & 18 deletions Source/ReactiveProperty.Core/ReactiveCommandSlim.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,20 @@ public ReactiveCommandSlim(IObservable<bool> canExecuteSource, IReadOnlyReactive
/// Subscribe execute.
/// </summary>
public IDisposable Subscribe(Action onNext)
=> this.Subscribe(new DelegateObserver(onNext));
=> Subscribe(new DelegateObserver(onNext));
}

/// <summary>
/// <see cref="ICommand"/> implementation for ReactiveProperty.
/// </summary>
public class ReactiveCommandSlim<T> : ICommand, IObservable<T?>, IObserver<bool>, IObserverLinkedList<T?>, IDisposable
public class ReactiveCommandSlim<T> : ICommand, IObservable<T>, IObserver<bool>, IObserverLinkedList<T>, IDisposable
{
private readonly IReadOnlyReactiveProperty<bool>? _sharedCanExecute;
private readonly IReadOnlyReactiveProperty<bool>? _canExecuteSource;
private readonly Action? _disposeAction;
private bool _canExecute = true;
private ObserverNode<T?>? _root;
private ObserverNode<T?>? _last;
private ObserverNode<T>? _root;
private ObserverNode<T>? _last;

/// <inheritdoc />
public event EventHandler? CanExecuteChanged;
Expand Down Expand Up @@ -153,10 +153,10 @@ void canExecute_PropertyChanged(object? sender, PropertyChangedEventArgs e)
}

/// <inheritdoc />
public bool CanExecute(T? parameter) => _canExecute;
public bool CanExecute(T parameter) => _canExecute;

/// <inheritdoc />
public void Execute(T? parameter)
public void Execute(T parameter)
{
if (_canExecute is false) return;

Expand All @@ -172,15 +172,14 @@ public void Execute(T? parameter)
/// <summary>
/// Subscribe execute.
/// </summary>
public IDisposable Subscribe(Action<T?> onNext)
=> this.Subscribe(new DelegateObserver<T?>(onNext));

public IDisposable Subscribe(Action<T> onNext)
=> Subscribe(new DelegateObserver<T>(onNext));

/// <inheritdoc />
bool ICommand.CanExecute(object? parameter) => CanExecute((T?)parameter);
bool ICommand.CanExecute(object? parameter) => CanExecute((T)parameter!);

/// <inheritdoc />
void ICommand.Execute(object? parameter) => Execute((T?)parameter);
void ICommand.Execute(object? parameter) => Execute((T)parameter!);

/// <summary>
/// Notifies the provider that an observer is to receive notifications.
Expand All @@ -190,7 +189,7 @@ public IDisposable Subscribe(Action<T?> onNext)
/// A reference to an interface that allows observers to stop receiving notifications before
/// the provider has finished sending them.
/// </returns>
public IDisposable Subscribe(IObserver<T?> observer)
public IDisposable Subscribe(IObserver<T> observer)
{
if (IsDisposed)
{
Expand All @@ -199,7 +198,7 @@ public IDisposable Subscribe(IObserver<T?> observer)
}

// subscribe node, node as subscription.
var next = new ObserverNode<T?>(this, observer);
var next = new ObserverNode<T>(this, observer);
if (_root == null)
{
_root = _last = next;
Expand All @@ -213,7 +212,7 @@ public IDisposable Subscribe(IObserver<T?> observer)
return next;
}

void IObserverLinkedList<T?>.UnsubscribeNode(ObserverNode<T?> node)
void IObserverLinkedList<T>.UnsubscribeNode(ObserverNode<T> node)
{
if (node == _root)
{
Expand Down Expand Up @@ -255,6 +254,8 @@ public void Dispose()
node.OnCompleted();
node = node.Next;
}

GC.SuppressFinalize(this);
}

void IObserver<bool>.OnCompleted() => _canExecute = false;
Expand Down Expand Up @@ -338,9 +339,9 @@ public static ReactiveCommandSlim WithSubscribe(this ReactiveCommandSlim self, A
/// <param name="onNext">Action</param>
/// <param name="postProcess">Handling of the subscription.</param>
/// <returns>Same of self argument</returns>
public static ReactiveCommandSlim<T> WithSubscribe<T>(this ReactiveCommandSlim<T> self, Action<T?> onNext, Action<IDisposable>? postProcess = null)
public static ReactiveCommandSlim<T> WithSubscribe<T>(this ReactiveCommandSlim<T> self, Action<T> onNext, Action<IDisposable>? postProcess = null)
{
var d = self.Subscribe(new DelegateObserver<T?>(onNext));
var d = self.Subscribe(new DelegateObserver<T>(onNext));
postProcess?.Invoke(d);
return self;
}
Expand All @@ -366,9 +367,9 @@ public static ReactiveCommandSlim WithSubscribe(this ReactiveCommandSlim self, A
/// <param name="onNext">Action</param>
/// <param name="disposable">The return value of self.Subscribe(onNext)</param>
/// <returns>Same of self argument</returns>
public static ReactiveCommandSlim<T> WithSubscribe<T>(this ReactiveCommandSlim<T> self, Action<T?> onNext, out IDisposable disposable)
public static ReactiveCommandSlim<T> WithSubscribe<T>(this ReactiveCommandSlim<T> self, Action<T> onNext, out IDisposable disposable)
{
disposable = self.Subscribe(new DelegateObserver<T?>(onNext));
disposable = self.Subscribe(new DelegateObserver<T>(onNext));
return self;
}
}
Expand Down

0 comments on commit a9cb8ff

Please sign in to comment.