Skip to content

Commit

Permalink
feat: remove UIComponent's static ClearCache method
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Because of the removal of reflection, the UIComponent attribute cache has been removed. UIComponent's static ClearCache method has been removed, as well.
  • Loading branch information
jonisavo committed Oct 17, 2022
1 parent eed6208 commit f236780
Show file tree
Hide file tree
Showing 14 changed files with 14 additions and 257 deletions.
4 changes: 1 addition & 3 deletions Assets/UIComponents.Benchmarks/BenchmarkUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ namespace UIComponents.Benchmarks
{
public static class BenchmarkUtils
{
public const string Version = "0.23.0.0";
public const string Version = "0.27.0.0";

private static SampleGroup[] GetProfilerMarkers()
{
return new[]
{
new SampleGroup("UIComponent.DependencySetup"),
new SampleGroup("UIComponent.CacheSetup"),
new SampleGroup("UIComponent.PostHierarchySetup"),
};
}
Expand All @@ -26,7 +25,6 @@ public static void MeasureComponentInitWithColdCache<TComponent>() where TCompon
})
.SetUp(() =>
{
UIComponent.ClearCache<TComponent>();
DiContext.Current.Container.Clear();
})
.SampleGroup(new SampleGroup("Cold Cache Time"))
Expand Down
62 changes: 0 additions & 62 deletions Assets/UIComponents.Benchmarks/UIComponentFieldCacheBenchmarks.cs

This file was deleted.

This file was deleted.

14 changes: 13 additions & 1 deletion Assets/UIComponents.Tests/DependencyInjectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,18 @@ public void Throws_If_No_Provider_Exists()

Assert.That(exception.Message, Is.EqualTo("No provider found for IDependency"));
}

[Test]
public void Throws_If_No_Provider_Exists_With_Non_Generic_Method()
{
var injector = new DependencyInjector(DiContext.Current.Container);

var exception = Assert.Throws<MissingProviderException>(
() => injector.Provide(typeof(IDependency))
);

Assert.That(exception.Message, Is.EqualTo("No provider found for IDependency"));
}
}

[TestFixture]
Expand Down Expand Up @@ -192,4 +204,4 @@ public void Creates_New_Transient_Instance()
}
}
}
}
}
43 changes: 0 additions & 43 deletions Assets/UIComponents.Tests/UIComponentCacheTests.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/UIComponents.Tests/UIComponentCacheTests.cs.meta

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/UIComponents/Core/Cache.meta

This file was deleted.

45 changes: 0 additions & 45 deletions Assets/UIComponents/Core/Cache/FieldCache.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/UIComponents/Core/Cache/FieldCache.cs.meta

This file was deleted.

17 changes: 0 additions & 17 deletions Assets/UIComponents/Core/Cache/UIComponentCache.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/UIComponents/Core/Cache/UIComponentCache.cs.meta

This file was deleted.

34 changes: 0 additions & 34 deletions Assets/UIComponents/Core/Internal/TypeUtils.cs

This file was deleted.

3 changes: 0 additions & 3 deletions Assets/UIComponents/Core/Internal/TypeUtils.cs.meta

This file was deleted.

26 changes: 0 additions & 26 deletions Assets/UIComponents/Core/UIComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using UIComponents.Cache;
using UIComponents.DependencyInjection;
using UIComponents.Internal;
using Unity.Profiling;
Expand All @@ -26,23 +25,6 @@ namespace UIComponents
[Dependency(typeof(IUIComponentLogger), provide: typeof(UIComponentDebugLogger))]
public abstract class UIComponent : VisualElement
{
private static readonly Dictionary<Type, UIComponentCache> CacheDictionary =
new Dictionary<Type, UIComponentCache>();

/// <summary>
/// Clears the cache of the UIComponent. Used primarily for testing.
/// </summary>
/// <typeparam name="TComponent">Component type</typeparam>
public static void ClearCache<TComponent>() where TComponent : UIComponent
{
CacheDictionary.Remove(typeof(TComponent));
}

internal static bool TryGetCache<TComponent>(out UIComponentCache cache) where TComponent : UIComponent
{
return CacheDictionary.TryGetValue(typeof(TComponent), out cache);
}

/// <summary>
/// The IAssetResolver used by this UIComponent.
/// Defaults to <see cref="ResourcesAssetResolver"/>.
Expand Down Expand Up @@ -74,8 +56,6 @@ public abstract class UIComponent : VisualElement

private static readonly ProfilerMarker DependencySetupProfilerMarker =
new ProfilerMarker("UIComponent.DependencySetup");
private static readonly ProfilerMarker CacheSetupProfilerMarker =
new ProfilerMarker("UIComponent.CacheSetup");
private static readonly ProfilerMarker PostHierarchySetupProfilerMarker =
new ProfilerMarker("UIComponent.PostHierarchySetup");

Expand All @@ -84,13 +64,7 @@ public abstract class UIComponent : VisualElement
/// </summary>
protected UIComponent()
{
CacheSetupProfilerMarker.Begin();

_componentType = GetType();
if (!CacheDictionary.ContainsKey(_componentType))
CacheDictionary.Add(_componentType, new UIComponentCache(_componentType));

CacheSetupProfilerMarker.End();

DependencySetupProfilerMarker.Begin();

Expand Down

0 comments on commit f236780

Please sign in to comment.