Skip to content

Commit 8e70ae2

Browse files
chore(common): clean up async void in favor of async Task
1 parent 938d202 commit 8e70ae2

File tree

8 files changed

+100
-99
lines changed

8 files changed

+100
-99
lines changed

_contentTemplates/common/general-info.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#event-callback-can-be-async
2-
>tip The event is an `EventCallback` and its type can be `void`, or it can also be asynchronous and return `async Task`.
2+
>tip The event is an `EventCallback` and it can be syncronous (return `void`), or it can also be asynchronous and return `async Task`.
33
#end
44

55
#ensure-nuget-packge-for-upgrade

components/treeview/data-binding/load-on-demand.md

Lines changed: 90 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,102 +21,103 @@ The **example** below shows how you can handle load on demand in detail. It uses
2121
>caption Load on Demand in a TreeView with sample handling of the various cases. Review the code comments for details.
2222
2323
````CSHTML
24-
@using Telerik.DataSource.Extensions //used for the .AddRange() extension method
24+
@using Telerik.DataSource.Extensions
25+
@* used for the .AddRange() extension method *@
2526
2627
<TelerikTreeView Data="@HierarchicalData" OnExpand="@LoadChildren">
27-
<TreeViewBindings>
28-
<TreeViewBinding TextField="Category" ItemsField="Products" />
29-
<TreeViewBinding Level="1" TextField="ProductName" />
30-
</TreeViewBindings>
28+
<TreeViewBindings>
29+
<TreeViewBinding TextField="Category" ItemsField="Products" />
30+
<TreeViewBinding Level="1" TextField="ProductName" />
31+
</TreeViewBindings>
3132
</TelerikTreeView>
3233
3334
@code {
34-
public List<ProductCategoryItem> HierarchicalData { get; set; }
35-
36-
public class ProductCategoryItem
37-
{
38-
public string Category { get; set; }
39-
public int CategoryId { get; set; } //will be used to identify the node, not for rendering in this example
40-
public List<ProductItem> Products { get; set; }
41-
public bool Expanded { get; set; }
42-
public bool HasChildren { get; set; }
43-
}
44-
45-
public class ProductItem
46-
{
47-
public string ProductName { get; set; }
48-
// the following fields are to denote you can keep having hierarchy further down. They are not required
49-
// they are not really used in this example and you would have a collection of child items too
50-
// see the information about multiple data bindings earlier in this article on using them
51-
public bool Expanded { get; set; }
52-
public bool HasChildren { get; set; }
53-
}
54-
55-
protected override void OnInitialized()
56-
{
57-
LoadRootHierarchical();
58-
}
59-
60-
private void LoadRootHierarchical()
61-
{
62-
HierarchicalData = new List<ProductCategoryItem>();
63-
64-
HierarchicalData.Add(new ProductCategoryItem
65-
{
66-
Category = "Category 1",
67-
HasChildren = true, // allow the user to expand the item and load children on demand
68-
CategoryId = 1 // an identifier for use in the service call for child items
69-
});
70-
71-
HierarchicalData.Add(new ProductCategoryItem
72-
{
73-
Category = "Category 2",
74-
HasChildren = true,
75-
CategoryId = 2
76-
});
77-
}
78-
79-
private async void LoadChildren(TreeViewExpandEventArgs args)
80-
{
81-
// check if the item is expanding, we don't need to do anything if it is collapsing
82-
// in this example we will also check the type of the model to know how to identify the node and what data to load. If you use only one model for all levels, you don't have to do this
83-
if (args.Expanded && args.Item is ProductCategoryItem)
84-
{
85-
ProductCategoryItem currCategory = args.Item as ProductCategoryItem;
86-
if (currCategory.Products?.Count > 0)
87-
{
88-
return; // item has been expanded before so it has data, don't load data again
89-
// alternatively, load it again but make sure to handle the child items correctly
90-
// either overwrite the entire collection, or use some other logic to append/merge
91-
}
92-
int itemIdentifier = currCategory.CategoryId;
93-
// in a similar fashion, you can identify the item that was just expanded through its properties
94-
// in this example, we will hardcode some data and logic for brevity
95-
// in a real case, you would probably await a remote endpoint/service
96-
97-
if (itemIdentifier == 2) // simulate no data for a certain node - the second in our example
98-
{
99-
currCategory.HasChildren = false; // remove the expand icon from the node
100-
101-
StateHasChanged(); // inform the UI that the data is changed
102-
103-
return;
104-
}
35+
public List<ProductCategoryItem> HierarchicalData { get; set; }
36+
37+
public class ProductCategoryItem
38+
{
39+
public string Category { get; set; }
40+
public int CategoryId { get; set; } //will be used to identify the node, not for rendering in this example
41+
public List<ProductItem> Products { get; set; }
42+
public bool Expanded { get; set; }
43+
public bool HasChildren { get; set; }
44+
}
45+
46+
public class ProductItem
47+
{
48+
public string ProductName { get; set; }
49+
// the following fields are to denote you can keep having hierarchy further down. They are not required
50+
// they are not really used in this example and you would have a collection of child items too
51+
// see the information about multiple data bindings earlier in this article on using them
52+
public bool Expanded { get; set; }
53+
public bool HasChildren { get; set; }
54+
}
55+
56+
protected override void OnInitialized()
57+
{
58+
LoadRootHierarchical();
59+
}
60+
61+
private void LoadRootHierarchical()
62+
{
63+
HierarchicalData = new List<ProductCategoryItem>();
64+
65+
HierarchicalData.Add(new ProductCategoryItem
66+
{
67+
Category = "Category 1",
68+
HasChildren = true, // allow the user to expand the item and load children on demand
69+
CategoryId = 1 // an identifier for use in the service call for child items
70+
});
71+
72+
HierarchicalData.Add(new ProductCategoryItem
73+
{
74+
Category = "Category 2",
75+
HasChildren = true,
76+
CategoryId = 2
77+
});
78+
}
79+
80+
private async Task LoadChildren(TreeViewExpandEventArgs args)
81+
{
82+
// check if the item is expanding, we don't need to do anything if it is collapsing
83+
// in this example we will also check the type of the model to know how to identify the node and what data to load. If you use only one model for all levels, you don't have to do this
84+
if (args.Expanded && args.Item is ProductCategoryItem)
85+
{
86+
ProductCategoryItem currCategory = args.Item as ProductCategoryItem;
87+
if (currCategory.Products?.Count > 0)
88+
{
89+
return; // item has been expanded before so it has data, don't load data again
90+
// alternatively, load it again but make sure to handle the child items correctly
91+
// either overwrite the entire collection, or use some other logic to append/merge
92+
}
93+
int itemIdentifier = currCategory.CategoryId;
94+
// in a similar fashion, you can identify the item that was just expanded through its properties
95+
// in this example, we will hardcode some data and logic for brevity
96+
// in a real case, you would probably await a remote endpoint/service
97+
98+
if (itemIdentifier == 2) // simulate no data for a certain node - the second in our example
99+
{
100+
currCategory.HasChildren = false; // remove the expand icon from the node
101+
102+
StateHasChanged(); // inform the UI that the data is changed
103+
104+
return;
105+
}
105106
106107
// data requested and received for a certain node
107-
List<ProductItem> theProducts = new List<ProductItem>() {
108-
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 1" },
109-
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 2" }
110-
};
111-
112-
// one way to add child elements to a collection
113-
currCategory.Products = new List<ProductItem>();
114-
currCategory.Products.AddRange<ProductItem>(theProducts);
115-
// the AddRange() method comes from the Telerik.DataSource.Extensions
116-
117-
StateHasChanged(); // inform the UI that the data is changed
118-
}
119-
}
108+
List<ProductItem> theProducts = new List<ProductItem>() {
109+
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 1" },
110+
new ProductItem { ProductName= $"Category {itemIdentifier} - Product 2" }
111+
};
112+
113+
// one way to add child elements to a collection
114+
currCategory.Products = new List<ProductItem>();
115+
currCategory.Products.AddRange<ProductItem>(theProducts);
116+
// the AddRange() method comes from the Telerik.DataSource.Extensions
117+
118+
StateHasChanged(); // inform the UI that the data is changed
119+
}
120+
}
120121
}
121122
````
122123

components/treeview/events.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The `OnExpand` event fires when the user expands or collapses a node (either wit
3131
3232
//event handler
3333
34-
async void ExpandCollapseHandler(TreeViewExpandEventArgs args)
34+
async Task ExpandCollapseHandler(TreeViewExpandEventArgs args)
3535
{
3636
TreeItem node = args.Item as TreeItem; // Use your actual model(s) for the cast
3737

knowledge-base/change-theme-runtime.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ var themeChanger = {
8181
<TelerikButton OnClick="ChangeTheme">Change from Default to Material Built-in Theme</TelerikButton>
8282
8383
@code {
84-
async void ChangeTheme()
84+
async Task ChangeTheme()
8585
{
8686
// use the new URL you will use - it can be relative and/or point to a custom theme
8787
string newThemeUrl = "https://unpkg.com/@progress/kendo-theme-material@latest/dist/all.css";

knowledge-base/common-validation-error-in-tooltip.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ There are several key aspects in implementing this:
9898
9999
TextValidationModel validationModel = new TextValidationModel() { LengthField = "Too long text" };
100100
101-
async void HideTooltip()
101+
async Task HideTooltip()
102102
{
103103
await AnimationContainer.HideAsync();
104104
// you may also want to create your own EditContext and hook to its OnValidationStateChanged event to hide the tooltip
105105
}
106106
107-
async void ShowTooltip()
107+
async Task ShowTooltip()
108108
{
109109
await AnimationContainer.ShowAsync();
110110
}

knowledge-base/dropdown-cascading.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ else if(!string.IsNullOrEmpty(orderStatusMessage))
139139
}
140140
141141
// sample notification of success and reseting of the process, data classes
142-
async void SendOrder()
142+
async Task SendOrder()
143143
{
144144
CurrentOrder = new Order();
145145
orderStatusMessage = "Thank you for your order!";
@@ -277,7 +277,7 @@ else if (!string.IsNullOrEmpty(orderStatusMessage))
277277
}
278278
279279
// sample notification of success and reseting of the process, data classes
280-
async void SendOrder()
280+
async Task SendOrder()
281281
{
282282
CurrentOrder = new Order();
283283
orderStatusMessage = "Thank you for your order!";
@@ -430,7 +430,7 @@ else if (!string.IsNullOrEmpty(orderStatusMessage))
430430
}
431431
432432
// sample notification of success and resetting of the process, data classes
433-
async void SendOrder()
433+
async Task SendOrder()
434434
{
435435
CurrentOrder = new Order();
436436
orderStatusMessage = "Thank you for your order!";

knowledge-base/grid-force-refresh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ When using manual operations through the [OnRead event](https://docs.telerik.com
6868
public ObservableCollection<Employee> GridData { get; set; } = new ObservableCollection<Employee>(); //prevent null reference errors by intializing the field
6969
DataSourceRequest LastRequest { get; set; }//store the last request so we can repeat it when changing the data
7070
71-
async void ChangeData()
71+
async Task ChangeData()
7272
{
7373
SourceData = GenerateData(DateTime.Now.Millisecond.ToString());
7474
await LoadData();//repeat the last request when changing data

knowledge-base/window-access-dom-element-on-show.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ Comments in the sample below provide more explanations:
5858
@code{
5959
bool ShowWindow { get; set; }
6060
61-
private async void ShowWindowAndCallJs()
61+
async Task ShowWindowAndCallJs()
6262
{
6363
ShowWindow = true;
6464

0 commit comments

Comments
 (0)