Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/ReactiveUI.Fody.Tests/ReactiveUI.Fody.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="PublicApiGenerator" Version="8.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
<PackageReference Include="PublicApiGenerator" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Shouldly" Version=" 3.0.0" />
<PackageReference Include="Shouldly" Version="3.0.2" />
<PackageReference Include="System.Reactive" Version="4.0.0" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="4.0.0" />
</ItemGroup>
Expand Down
25 changes: 11 additions & 14 deletions src/ReactiveUI.Tests/API/ApiApprovalTests.ReactiveUI.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -458,13 +458,8 @@ namespace ReactiveUI
public string PropertyName { get; set; }
}
public delegate void PropertyChangingEventHandler(object sender, ReactiveUI.PropertyChangingEventArgs e);
public abstract class ReactiveCommand : ReactiveUI.IHandleObservableErrors, System.IDisposable, System.Windows.Input.ICommand
public class static ReactiveCommand
{
protected ReactiveCommand() { }
public abstract System.IObservable<bool> CanExecute { get; }
public abstract System.IObservable<bool> IsExecuting { get; }
public abstract System.IObservable<System.Exception> ThrownExceptions { get; }
public event System.EventHandler System.Windows.Input.ICommand.CanExecuteChanged;
public static ReactiveUI.ReactiveCommand<System.Reactive.Unit, System.Reactive.Unit> Create(System.Action execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
public static ReactiveUI.ReactiveCommand<System.Reactive.Unit, TResult> Create<TResult>(System.Func<TResult> execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
public static ReactiveUI.ReactiveCommand<TParam, System.Reactive.Unit> Create<TParam>(System.Action<TParam> execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
Expand All @@ -480,11 +475,6 @@ namespace ReactiveUI
public static ReactiveUI.ReactiveCommand<TParam, TResult> CreateFromTask<TParam, TResult>(System.Func<TParam, System.Threading.CancellationToken, System.Threading.Tasks.Task<TResult>> execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
public static ReactiveUI.ReactiveCommand<TParam, System.Reactive.Unit> CreateFromTask<TParam>(System.Func<TParam, System.Threading.Tasks.Task> execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
public static ReactiveUI.ReactiveCommand<TParam, System.Reactive.Unit> CreateFromTask<TParam>(System.Func<TParam, System.Threading.CancellationToken, System.Threading.Tasks.Task> execute, System.IObservable<bool> canExecute = null, System.Reactive.Concurrency.IScheduler outputScheduler = null) { }
public void Dispose() { }
protected abstract void Dispose(bool disposing);
protected abstract bool ICommandCanExecute(object parameter);
protected abstract void ICommandExecute(object parameter);
protected void OnCanExecuteChanged() { }
}
public class ReactiveCommand<TParam, TResult> : ReactiveUI.ReactiveCommandBase<TParam, TResult>
{
Expand All @@ -496,12 +486,19 @@ namespace ReactiveUI
public override System.IObservable<TResult> Execute(TParam parameter = null) { }
public override System.IDisposable Subscribe(System.IObserver<TResult> observer) { }
}
public abstract class ReactiveCommandBase<TParam, TResult> : ReactiveUI.ReactiveCommand, System.IObservable<TResult>
public abstract class ReactiveCommandBase<TParam, TResult> : ReactiveUI.IHandleObservableErrors, System.IDisposable, System.IObservable<TResult>, System.Windows.Input.ICommand
{
protected ReactiveCommandBase() { }
public abstract System.IObservable<bool> CanExecute { get; }
public abstract System.IObservable<bool> IsExecuting { get; }
public abstract System.IObservable<System.Exception> ThrownExceptions { get; }
public event System.EventHandler System.Windows.Input.ICommand.CanExecuteChanged;
public void Dispose() { }
protected abstract void Dispose(bool disposing);
public abstract System.IObservable<TResult> Execute(TParam parameter = null);
protected override bool ICommandCanExecute(object parameter) { }
protected override void ICommandExecute(object parameter) { }
protected virtual bool ICommandCanExecute(object parameter) { }
protected virtual void ICommandExecute(object parameter) { }
protected void OnCanExecuteChanged() { }
public abstract System.IDisposable Subscribe(System.IObserver<TResult> observer);
}
public class static ReactiveCommandMixins
Expand Down
22 changes: 11 additions & 11 deletions src/ReactiveUI.Tests/CommandBindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ReactiveUI.Tests
{
public class FakeViewModel : ReactiveObject
{
public ReactiveCommand Cmd { get; protected set; }
public ReactiveCommand<Unit, Unit> Cmd { get; protected set; }

public FakeViewModel()
{
Expand Down Expand Up @@ -123,9 +123,9 @@ public void EventBinderBindsToImplicitEvent()

public class CommandBindViewModel : ReactiveObject
{
public ReactiveCommand _Command1;
public ReactiveCommand<int, Unit> _Command1;

public ReactiveCommand Command1
public ReactiveCommand<int, Unit> Command1
{
get => _Command1;
set => this.RaiseAndSetIfChanged(ref _Command1, value);
Expand All @@ -141,7 +141,7 @@ public ReactiveCommand<Unit, Unit> Command2

public CommandBindViewModel()
{
Command1 = ReactiveCommand.Create(() => { });
Command1 = ReactiveCommand.Create<int, Unit>(_ => Unit.Default);
Command2 = ReactiveCommand.Create(() => { });
}

Expand All @@ -163,7 +163,7 @@ public FakeNestedViewModel()
NestedCommand = ReactiveCommand.Create(() => { });
}

public ReactiveCommand NestedCommand { get; protected set; }
public ReactiveCommand<Unit, Unit> NestedCommand { get; protected set; }
}

public class CustomClickButton : Button
Expand Down Expand Up @@ -235,7 +235,7 @@ public void CommandBindByNameWireup()
var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Assert.Equal(vm.Command1, view.Command1.Command);

var newCmd = ReactiveCommand.Create(() => { });
var newCmd = ReactiveCommand.Create<int>(_ => { });
vm.Command1 = newCmd;
Assert.Equal(newCmd, view.Command1.Command);

Expand Down Expand Up @@ -265,7 +265,7 @@ public void CommandBindSetsInitialEnabledState_True()
var view = new CommandBindView { ViewModel = vm };

var canExecute1 = new BehaviorSubject<bool>(true);
var cmd1 = ReactiveCommand.Create(() => { }, canExecute1);
var cmd1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
vm.Command1 = cmd1;

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Expand All @@ -280,7 +280,7 @@ public void CommandBindSetsDisablesCommandWhenCanExecuteChanged()
var view = new CommandBindView { ViewModel = vm };

var canExecute1 = new BehaviorSubject<bool>(true);
var cmd1 = ReactiveCommand.Create(() => { }, canExecute1);
var cmd1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
vm.Command1 = cmd1;

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Expand All @@ -299,7 +299,7 @@ public void CommandBindSetsInitialEnabledState_False()
var view = new CommandBindView { ViewModel = vm };

var canExecute1 = new BehaviorSubject<bool>(false);
var cmd1 = ReactiveCommand.Create(() => { }, canExecute1);
var cmd1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
vm.Command1 = cmd1;

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Expand All @@ -314,7 +314,7 @@ public void CommandBindRaisesCanExecuteChangedOnBind()
var view = new CommandBindView { ViewModel = vm };

var canExecute1 = new BehaviorSubject<bool>(true);
var cmd1 = ReactiveCommand.Create(() => { }, canExecute1);
var cmd1 = ReactiveCommand.Create<int>(_ => { }, canExecute1);
vm.Command1 = cmd1;

var disp = view.BindCommand(vm, x => x.Command1, x => x.Command1);
Expand All @@ -323,7 +323,7 @@ public void CommandBindRaisesCanExecuteChangedOnBind()

// Now change to a disabled cmd
var canExecute2 = new BehaviorSubject<bool>(false);
var cmd2 = ReactiveCommand.Create(() => { }, canExecute2);
var cmd2 = ReactiveCommand.Create<int>(_ => { }, canExecute2);
vm.Command1 = cmd2;

Assert.False(view.Command1.IsEnabled);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void CommandBindToExplicitEventWireup()

public class FakeViewModel : ReactiveObject
{
public ReactiveCommand Cmd { get; protected set; }
public ReactiveCommand<Unit, Unit> Cmd { get; protected set; }

public FakeViewModel()
{
Expand Down
14 changes: 7 additions & 7 deletions src/ReactiveUI.Tests/ReactiveUI.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.8.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.9.0" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit" Version="2.4.0" />
<PackageReference Include="xunit.runner.console" Version="2.4.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.0" />
<PackageReference Include="Xunit.StaFact" Version="0.2.17" />
<PackageReference Include="Shouldly" Version=" 3.0.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.console" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
<PackageReference Include="Xunit.StaFact" Version="0.3.5" />
<PackageReference Include="Shouldly" Version=" 3.0.2" />
<PackageReference Include="Microsoft.Reactive.Testing" Version="4.0.0" />
<PackageReference Include="PublicApiGenerator" Version="8.0.0" />
<PackageReference Include="PublicApiGenerator" Version="8.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/ReactiveUI.Tests/WeakEventManagerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class WeakEventManagerTest
public void ButtonDoesNotLeakTest()
{
var button = new Button();
ReactiveCommand command = ReactiveCommand.Create(() => { });
var command = ReactiveCommand.Create(() => { });
button.Command = command;

var buttonRef = new WeakReference(button);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ public IReactiveBinding<TView, TViewModel, TProp> BindCommand<TView, TViewModel,

IDisposable bindingDisposable = BindCommandInternal(source, view, controlExpression, Observable.Defer(() => Observable.Return(withParameter())), toEvent, cmd =>
{
var rc = cmd as ReactiveCommand;
var rc = cmd as IReactiveCommand;
if (rc == null)
{
return new RelayCommand(cmd.CanExecute, _ => cmd.Execute(withParameter()));
}

var ret = ReactiveCommand.Create(() => ((ICommand)rc).Execute(null), rc.CanExecute);
return ret;
return ReactiveCommand.Create(() => ((ICommand)rc).Execute(null), rc.CanExecute);
});

return new ReactiveBinding<TView, TViewModel, TProp>(
Expand Down
4 changes: 2 additions & 2 deletions src/ReactiveUI/EventManagers/WeakEventManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ public bool Matches(object source, TEventHandler handler)
ReferenceEquals(_source.Target, source) &&
_originalHandler != null &&
(ReferenceEquals(_originalHandler.Target, handler) ||
_originalHandler.Target is PropertyChangedEventHandler eventHandler &&
(_originalHandler.Target is PropertyChangedEventHandler eventHandler &&
handler is PropertyChangedEventHandler &&
Equals(
eventHandler.Target,
(handler as PropertyChangedEventHandler)?.Target));
(handler as PropertyChangedEventHandler)?.Target)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ namespace ReactiveUI
/// <summary>
/// AutoSuspend-based Application. To use AutoSuspend with WinRT, change your
/// Application to inherit from this class, then call:
///
/// Locator.Current.GetService.<ISuspensionHost>().SetupDefaultSuspendResume();
/// Locator.Current.GetService.&lt;ISuspensionHost&gt;().SetupDefaultSuspendResume();
/// This will register your suspension host.
/// </summary>
public class AutoSuspendHelper : IEnableLogger
{
Expand Down
36 changes: 36 additions & 0 deletions src/ReactiveUI/ReactiveCommand/IReactiveCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;

namespace ReactiveUI
{
/// <summary>
/// Encapsulates a user action behind a reactive interface.
/// This is for interop inside for the command binding.
/// Not meant for external use due to the fact it doesn't implement ICommand
/// to force the user to favor the Reactive style command execution.
/// </summary>
internal interface IReactiveCommand : IDisposable, IHandleObservableErrors
{
/// <summary>
/// Gets an observable whose value indicates whether the command is currently executing.
/// </summary>
/// <remarks>
/// This observable can be particularly useful for updating UI, such as showing an activity indicator whilst a command
/// is executing.
/// </remarks>
IObservable<bool> IsExecuting { get; }

/// <summary>
/// Gets an observable whose value indicates whether the command can currently execute.
/// </summary>
/// <remarks>
/// The value provided by this observable is governed both by any <c>canExecute</c> observable provided during
/// command creation, as well as the current execution status of the command. A command that is currently executing
/// will always yield <c>false</c> from this observable, even if the <c>canExecute</c> pipeline is currently <c>true</c>.
/// </remarks>
IObservable<bool> CanExecute { get; }
}
}
Loading