From af58373f8e8edb26cf67514ef63765ed72a6a0c8 Mon Sep 17 00:00:00 2001 From: Oleksandr Liakhevych Date: Sun, 27 Aug 2023 23:43:55 +0300 Subject: [PATCH] Remove KeySelector support for now - I'm not sure how it should work --- .../Elements/Internal/ItemsSourceComponent.cs | 21 ++++++------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs b/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs index 8028addf..dbe4e69c 100644 --- a/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs +++ b/src/BlazorBindings.Maui/Elements/Internal/ItemsSourceComponent.cs @@ -18,14 +18,10 @@ internal class ItemsSourceComponent : NativeControlComponentBas [Parameter] public Action> CollectionSetter { get; set; } - [Parameter] - public Func KeySelector { get; set; } - - private TControl _parent; public object TargetElement => _parent; - private HashSet _keys; + private readonly HashSet _keys = new(); protected override RenderFragment GetChildContent() => builder => { @@ -35,16 +31,11 @@ protected override RenderFragment GetChildContent() => builder => int index = 0; foreach (var item in Items) { - var key = KeySelector == null ? item : KeySelector(item); - if (KeySelector == null) - { - // Blazor doesn't allow duplicate keys. Therefore we add keys until the first duplicate. - // In case KeySelector is provided, we don't check for that here, since it's user's responsibility now. - _keys ??= new(); - shouldAddKey &= _keys.Add(key); - if (!shouldAddKey) - key = null; - } + object key = item; + // Blazor doesn't allow duplicate keys. Therefore we add keys only until the first duplicate. + shouldAddKey &= _keys.Add(key); + if (!shouldAddKey) + key = null; builder.OpenComponent(1); builder.SetKey(key);