Skip to content

Commit

Permalink
Prefer async/await over returning Task
Browse files Browse the repository at this point in the history
  • Loading branch information
Zhiyuan-Amos committed Jan 24, 2022
1 parent 6a4135d commit 3b761d3
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Client/Pages/Calendar/Components/CreateUpdateForm.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ private async Task ToggleEndPicker() // can't extract w/ ToggleStartPicker() as
}
}

private Task Remove(IssueModel toRemove) => RemovedChanged.InvokeAsync(toRemove);
private async Task Remove(IssueModel toRemove) => await RemovedChanged.InvokeAsync(toRemove);
}
2 changes: 1 addition & 1 deletion Client/Services/Synchronizer/CompleteTaskCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class CompleteTaskCommand : ICommand

public CompleteTaskCommand(IJSRuntime js, CreateCompletedTaskModel model) => (_js, _model) = (js, model);

public Task Execute() => _js.InvokeVoidAsync("completeTask", _model).AsTask();
public async Task Execute() => await _js.InvokeVoidAsync("completeTask", _model).AsTask();
}
2 changes: 1 addition & 1 deletion Client/Services/Synchronizer/CreateImageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class CreateImageCommand : ICommand

public CreateImageCommand(IJSRuntime js, ImageModel model) => (_js, _model) = (js, model);

public Task Execute() => _js.InvokeVoidAsync("createImage", _model).AsTask();
public async Task Execute() => await _js.InvokeVoidAsync("createImage", _model).AsTask();
}
12 changes: 8 additions & 4 deletions Client/Services/Synchronizer/CreateIssueCommand.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Couple.Client.Data;
using Couple.Client.Model.Issue;
using Microsoft.JSInterop;

namespace Couple.Client.Services.Synchronizer;

public class CreateIssueCommand : ICommand
{
private readonly IJSRuntime _js;
private readonly AppDbContext _dbContext;
private readonly IssueModel _model;

public CreateIssueCommand(IJSRuntime js, IssueModel model) => (_js, _model) = (js, model);
public CreateIssueCommand(AppDbContext dbContext, IssueModel model) => (_dbContext, _model) = (dbContext, model);

public Task Execute() => _js.InvokeVoidAsync("createIssue", _model).AsTask();
public async Task Execute()
{
_dbContext.Issues.Add(_model);
await _dbContext.SaveChangesAsync();
}
}
2 changes: 1 addition & 1 deletion Client/Services/Synchronizer/DeleteImageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ public class DeleteImageCommand : ICommand

public DeleteImageCommand(IJSRuntime js, Guid guid) => (_js, _guid) = (js, guid);

public Task Execute() => _js.InvokeVoidAsync("deleteImage", _guid).AsTask();
public async Task Execute() => await _js.InvokeVoidAsync("deleteImage", _guid).AsTask();
}
12 changes: 8 additions & 4 deletions Client/Services/Synchronizer/DeleteIssueCommand.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
using Microsoft.JSInterop;
using Couple.Client.Data;

namespace Couple.Client.Services.Synchronizer;

public class DeleteIssueCommand : ICommand
{
private readonly AppDbContext _dbContext;
private readonly Guid _guid;
private readonly IJSRuntime _js;

public DeleteIssueCommand(IJSRuntime js, Guid guid) => (_js, _guid) = (js, guid);
public DeleteIssueCommand(AppDbContext dbContext, Guid guid) => (_dbContext, _guid) = (dbContext, guid);

public Task Execute() => _js.InvokeVoidAsync("deleteIssue", _guid).AsTask();
public async Task Execute()
{
_dbContext.Issues.Remove(new() { Id = _guid });
await _dbContext.SaveChangesAsync();
}
}
2 changes: 1 addition & 1 deletion Client/Services/Synchronizer/UpdateImageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ public class UpdateImageCommand : ICommand

public UpdateImageCommand(IJSRuntime js, ImageModel model) => (_js, _model) = (js, model);

public Task Execute() => _js.InvokeVoidAsync("updateImage", _model).AsTask();
public async Task Execute() => await _js.InvokeVoidAsync("updateImage", _model).AsTask();
}
12 changes: 8 additions & 4 deletions Client/Services/Synchronizer/UpdateIssueCommand.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
using Couple.Client.Data;
using Couple.Client.Model.Issue;
using Microsoft.JSInterop;

namespace Couple.Client.Services.Synchronizer;

public class UpdateIssueCommand : ICommand
{
private readonly IJSRuntime _js;
private readonly AppDbContext _dbContext;
private readonly IssueModel _model;

public UpdateIssueCommand(IJSRuntime js, IssueModel model) => (_js, _model) = (js, model);
public UpdateIssueCommand(AppDbContext dbContext, IssueModel model) => (_dbContext, _model) = (dbContext, model);

public Task Execute() => _js.InvokeVoidAsync("updateIssue", _model).AsTask();
public async Task Execute()
{
_dbContext.Issues.Update(_model);
await _dbContext.SaveChangesAsync();
}
}
2 changes: 1 addition & 1 deletion Client/Shared/BaseTopBar.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ public partial class BaseTopBar

[Inject] private Synchronizer Synchronizer { get; init; }

private Task Synchronize() => Synchronizer.SynchronizeAsync();
private async Task Synchronize() => await Synchronizer.SynchronizeAsync();
}

0 comments on commit 3b761d3

Please sign in to comment.