Improved ReactiveCommand.CreateFromTask

This commit is contained in:
2dust
2024-10-10 18:02:09 +08:00
parent 4f5362fdc4
commit a556bf9487
14 changed files with 209 additions and 202 deletions

View File

@@ -57,52 +57,52 @@ namespace ServiceLib.ViewModels
x => x.SelectedSource,
selectedSource => selectedSource != null && !selectedSource.outboundTag.IsNullOrEmpty());
RuleAddCmd = ReactiveCommand.Create(() =>
RuleAddCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleEditAsync(true);
await RuleEditAsync(true);
});
ImportRulesFromFileCmd = ReactiveCommand.CreateFromTask(async () =>
{
await _updateView?.Invoke(EViewAction.ImportRulesFromFile, null);
});
ImportRulesFromClipboardCmd = ReactiveCommand.Create(() =>
ImportRulesFromClipboardCmd = ReactiveCommand.CreateFromTask(async () =>
{
ImportRulesFromClipboardAsync(null);
await ImportRulesFromClipboardAsync(null);
});
ImportRulesFromUrlCmd = ReactiveCommand.Create(() =>
ImportRulesFromUrlCmd = ReactiveCommand.CreateFromTask(async () =>
{
ImportRulesFromUrl();
await ImportRulesFromUrl();
});
RuleRemoveCmd = ReactiveCommand.Create(() =>
RuleRemoveCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleRemoveAsync();
await RuleRemoveAsync();
}, canEditRemove);
RuleExportSelectedCmd = ReactiveCommand.Create(() =>
RuleExportSelectedCmd = ReactiveCommand.CreateFromTask(async () =>
{
RuleExportSelectedAsync();
await RuleExportSelectedAsync();
}, canEditRemove);
MoveTopCmd = ReactiveCommand.Create(() =>
MoveTopCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Top);
await MoveRule(EMove.Top);
}, canEditRemove);
MoveUpCmd = ReactiveCommand.Create(() =>
MoveUpCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Up);
await MoveRule(EMove.Up);
}, canEditRemove);
MoveDownCmd = ReactiveCommand.Create(() =>
MoveDownCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Down);
await MoveRule(EMove.Down);
}, canEditRemove);
MoveBottomCmd = ReactiveCommand.Create(() =>
MoveBottomCmd = ReactiveCommand.CreateFromTask(async () =>
{
MoveRule(EMove.Bottom);
await MoveRule(EMove.Bottom);
}, canEditRemove);
SaveCmd = ReactiveCommand.Create(() =>
SaveCmd = ReactiveCommand.CreateFromTask(async () =>
{
SaveRoutingAsync();
await SaveRoutingAsync();
});
}
@@ -201,7 +201,7 @@ namespace ServiceLib.ViewModels
}
}
public void MoveRule(EMove eMove)
public async Task MoveRule(EMove eMove)
{
if (SelectedSource is null || SelectedSource.outboundTag.IsNullOrEmpty())
{
@@ -285,7 +285,7 @@ namespace ServiceLib.ViewModels
}
}
private async void ImportRulesFromUrl()
private async Task ImportRulesFromUrl()
{
var url = SelectedRouting.url;
if (Utils.IsNullOrEmpty(url))