Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Small performance update for rendering list items #1476

Merged
merged 5 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:err
dotnet_style_require_accessibility_modifiers = for_non_interface_members:error

# Require var all the time.
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_for_built_in_types = true:suggestion
csharp_style_var_when_type_is_apparent = true:suggestion
csharp_style_var_elsewhere = true:suggestion

# Expression-level preferences
Expand Down
28 changes: 18 additions & 10 deletions src/Core/Components/List/ListComponentBase.razor
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,24 @@
{
private void RenderOptions(RenderTreeBuilder __builder)
{
bool genericItems = false;

if (Items is null)
{
@ChildContent
}
else
{
// get the first item to determine the type
TOption firstItem = Items.First();

Type t = firstItem.GetType();
vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Option<>))
{
genericItems = true;

}

foreach (TOption item in Items)
{
<FluentOption TOption="TOption"
Expand All @@ -30,26 +42,22 @@
{
@GetOptionText(item)
}

@{
Type t = item.GetType();

}
@if (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(Option<>))

@if (genericItems)
{
PropertyInfo? prop = t.GetProperty("Icon");

if (prop is not null)
{
(Icon Value, Color? Color, string? Slot) = ((Icon Value, Color? Color, string? Slot)) prop.GetValue(item)!;
(Icon Value, Color? Color, string? Slot) = ((Icon Value, Color? Color, string? Slot))prop.GetValue(item)!;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To validate, but if your Option<TType> class implements this interface, you could cast your object and have access to these properties:

var optionIcon = item as IOptionIcon;
var value = optionIcon?.Icon.Value;
...
internal interface IOptionIcon
{
    (Icon Value, Color? Color, string? Slot) Icon { get; set; }
}

if (Value != null)
{
<FluentIcon Value="@Value" Color="@Color" Slot="@Slot" />
}
}
}
}
</FluentOption>
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,40 @@

<h1>Hello, world!</h1>

Welcome to your new Fluent Blazor app.
Welcome to your new Fluent Blazor app.

<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>
<FluentSelect Items="@strings"></FluentSelect>



@code {
vnbaaij marked this conversation as resolved.
Show resolved Hide resolved
IEnumerable<string>? strings;
string? selectedValue;

private IEnumerable<string> GetLongListOfStrings()
{
IList<string> longListOfStrings = new List<string>();

for (int i = 0; i < 100; i++)
{
longListOfStrings.Add("123456");
}
return longListOfStrings;
}


protected override Task OnParametersSetAsync()
{
strings = GetLongListOfStrings();
return Task.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components" Version="4.*-* " />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.*-* " />
<PackageReference Include="Microsoft.FluentUI.AspNetCore.Components.Icons" Version="4.*-* " />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\..\..\src\Core\Microsoft.FluentUI.AspNetCore.Components.csproj" />
</ItemGroup>
</Project>
Loading