Cysharp / R3

The new future of dotnet/reactive and UniRx.
MIT License
1.72k stars 70 forks source link

About CanExecute of ReactiveCommand #169

Closed kimk-s closed 3 months ago

kimk-s commented 3 months ago

Thanks for your libraries!

I expected the Assert below to pass, but it failed. Can you please check if the Assert is correct?

var log = new List<string>();

var c = new ReactiveCommand<Unit>();
c.Subscribe(_ => log.Add("Executed"));

c.ChangeCanExecute(false);

c.Execute(Unit.Default);

Debug.Assert(log.Count == 0);
neuecc commented 3 months ago

I see, it seems to behave differently from UniRx. In many framework implementations of ICommand, CanExecute and Execute were not linked together. https://github.com/CommunityToolkit/dotnet/blob/7b53ae23dfc6a7fb12d0fc058b89b6e948f48448/src/CommunityToolkit.Mvvm/Input/RelayCommand%7BT%7D.cs The behavior follows that pattern. For determining whether execution is possible, please use the result of CanExecute (bind to enable/disable).

kimk-s commented 3 months ago

Your answers helped me a lot. Thank you very much for the explanation!