ReactiveCommand 不尊重 canExecute [英] ReactiveCommand not respecting canExecute
问题描述
也许我遗漏了一些东西,但是我无法获得 ReactiveCommand 以阻止基于 canExecute observable 的执行.
Perhaps I'm missing something, however I can't get ReactiveCommand to prevent execution based on the canExecute observable.
下面是我能想到的最简单的例子.我希望命令永远不会开火,但它确实如此.
Below is the simplest example I can conjure. I would expect the command to never fire, however it is.
我错过了什么?
void Main()
{
var canExecute = Observable.Return(false);
var myCommand = ReactiveCommand.CreateAsyncTask(canExecute, m => functions.doAllThings(m));
myCommand.Subscribe(x=>"executing".Dump());
myCommand.Execute("Tom"); // This fires the command. I would have expected it to block
}
static class functions
{
public static Task doAllThings(object message)
{
var result = Task.Run(() =>{
"running task...".Dump();
return "hello " + (string)message;});
return result;
}
}
注意 - 这是一个来自从另一个命令执行命令的分叉"问题.我相信这更多是核心问题.
Note - This is question is kind of a 'fork' from Executing a command from another command. I believe that this is more the core issue.
推荐答案
这是特意设计的.ReactiveUI 不会阻止您显式调用 Execute
/ExecuteAsync
,并且相信您知道自己在做什么™
This is by-design. ReactiveUI doesn't stop you from explicitly calling Execute
/ ExecuteAsync
, and trusts that You Know What You're Doing™
这篇关于ReactiveCommand 不尊重 canExecute的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!