ReactiveCommands - 以下解决方案是否等效?
ReactiveCommands - Are the following solutions equivalent?
解决方案 A)
public ReactiveCommand<Unit, Unit> CommandDoStuff => this._commandDoStuff;
private readonly ReactiveCommand<Unit, Unit> _commandDoStuff;
this._commandDoStuff = ReactiveCommand.CreateFromTask(async () =>
{
//pass in parameters directly, do stuff, handle output maybe with an interaction, return Unit;
var result = await DoStuff(this.Parameter);
SharedInteraction.Handle(result);
return;
});
this._commandDoStuff.Execute().Subscribe();
解决方案 B)
public ReactiveCommand<T, T> CommandDoStuff => this._commandDoStuff;
private readonly ReactiveCommand<T, T> _commandDoStuff;
this._commandDoStuff = ReactiveCommand.CreateFromTask(async (T) =>
{
//do stuff, return T
var result = await DoStuff(T);
return result;
});
this._commandDoStuff.Execute(T).Subscribe(t =>
{
//handle output maybe with an interaction
SharedInteraction.Handle(t);
return;
});
我知道这些问题很蹩脚,但这是为了避免提出基于意见的问题...
两种解决方案都是"valid"吗?
两种解决方案是否等效?如果不是,有什么区别?
是否有一种解决方案性能更高?
一种解决方案是否比另一种解决方案更容易出现错误?
一种解决方案是否比另一种更符合软件工程范例?
你明白我的意思了! :)
所以要避免基于意见的回答。我会尽我最大的努力坚持我所知道的。
Interactions
是关于控制流的。我的 ViewModel 中有一些功能正在发生,而我的 ViewModel 有控制权。我需要用户的输入才能完成此功能。我将显示一个 Interaction
以从用户那里获取该信息。
所以要回答,这取决于您需要在哪里显示信息。
当您订阅 ReactiveCommand
的执行时,您实际上是在订阅它的执行。这意味着命令将执行,然后 Subscribe()
中的代码将执行。如果您希望 Interaction
显示 ReactiveCommand
完成所需的信息,这将增加很少的价值。
也就是说,如果您只是通过 Interaction
提醒用户命令已完成,那么这可能不是问题。
性能将取决于操作是什么。
您是否有一个特定的范例,或者只是在寻找难以捉摸的 "Best Practices"?
一般来说,Stack Overflow 不喜欢这些开放式问题,因为没有具体的答案。
解决方案 A)
public ReactiveCommand<Unit, Unit> CommandDoStuff => this._commandDoStuff;
private readonly ReactiveCommand<Unit, Unit> _commandDoStuff;
this._commandDoStuff = ReactiveCommand.CreateFromTask(async () =>
{
//pass in parameters directly, do stuff, handle output maybe with an interaction, return Unit;
var result = await DoStuff(this.Parameter);
SharedInteraction.Handle(result);
return;
});
this._commandDoStuff.Execute().Subscribe();
解决方案 B)
public ReactiveCommand<T, T> CommandDoStuff => this._commandDoStuff;
private readonly ReactiveCommand<T, T> _commandDoStuff;
this._commandDoStuff = ReactiveCommand.CreateFromTask(async (T) =>
{
//do stuff, return T
var result = await DoStuff(T);
return result;
});
this._commandDoStuff.Execute(T).Subscribe(t =>
{
//handle output maybe with an interaction
SharedInteraction.Handle(t);
return;
});
我知道这些问题很蹩脚,但这是为了避免提出基于意见的问题...
两种解决方案都是"valid"吗?
两种解决方案是否等效?如果不是,有什么区别?
是否有一种解决方案性能更高?
一种解决方案是否比另一种解决方案更容易出现错误?
一种解决方案是否比另一种更符合软件工程范例?
你明白我的意思了! :)
所以要避免基于意见的回答。我会尽我最大的努力坚持我所知道的。
Interactions
是关于控制流的。我的 ViewModel 中有一些功能正在发生,而我的 ViewModel 有控制权。我需要用户的输入才能完成此功能。我将显示一个 Interaction
以从用户那里获取该信息。
所以要回答,这取决于您需要在哪里显示信息。
当您订阅 ReactiveCommand
的执行时,您实际上是在订阅它的执行。这意味着命令将执行,然后 Subscribe()
中的代码将执行。如果您希望 Interaction
显示 ReactiveCommand
完成所需的信息,这将增加很少的价值。
也就是说,如果您只是通过 Interaction
提醒用户命令已完成,那么这可能不是问题。
性能将取决于操作是什么。
您是否有一个特定的范例,或者只是在寻找难以捉摸的 "Best Practices"?
一般来说,Stack Overflow 不喜欢这些开放式问题,因为没有具体的答案。