From c95747af3ea3e6784a20b3ef197c579c1991ae15 Mon Sep 17 00:00:00 2001 From: Steve Sanderson Date: Tue, 9 Jan 2018 13:52:56 +0000 Subject: [PATCH] Remove some implementation code that isn't strictly needed (so far, at least) --- .../Rendering/BrowserRenderer.cs | 2 +- src/Microsoft.Blazor/Rendering/Renderer.cs | 29 +------------------ 2 files changed, 2 insertions(+), 29 deletions(-) diff --git a/src/Microsoft.Blazor.Browser/Rendering/BrowserRenderer.cs b/src/Microsoft.Blazor.Browser/Rendering/BrowserRenderer.cs index 367dc46f07..a3d28b2e51 100644 --- a/src/Microsoft.Blazor.Browser/Rendering/BrowserRenderer.cs +++ b/src/Microsoft.Blazor.Browser/Rendering/BrowserRenderer.cs @@ -50,7 +50,7 @@ namespace Microsoft.Blazor.Browser.Rendering componentId); _rootComponents.Add(component); - RenderComponent(component); + RenderComponent(componentId); } /// diff --git a/src/Microsoft.Blazor/Rendering/Renderer.cs b/src/Microsoft.Blazor/Rendering/Renderer.cs index d9f6ebf621..bb51ff4398 100644 --- a/src/Microsoft.Blazor/Rendering/Renderer.cs +++ b/src/Microsoft.Blazor/Rendering/Renderer.cs @@ -4,8 +4,6 @@ using Microsoft.Blazor.Components; using Microsoft.Blazor.RenderTree; using System; -using System.Collections.Generic; -using System.Runtime.CompilerServices; namespace Microsoft.Blazor.Rendering { @@ -21,15 +19,8 @@ namespace Microsoft.Blazor.Rendering // these reference descendant components and associated ComponentState instances. private readonly WeakValueDictionary _componentStateById = new WeakValueDictionary(); - private readonly ConditionalWeakTable _componentStateByComponent - = new ConditionalWeakTable(); private int _nextComponentId = 0; // TODO: change to 'long' when Mono .NET->JS interop supports it - // Ensure that explictly-added components (and transitively, their current descendants) - // aren't GCed. If we don't do this then the display layer (e.g., browser) might send - // us events for component IDs where the corresponding state has already been collected. - private readonly IList _topLevelComponents = new List(); - /// /// Associates the with the , assigning /// an identifier that is unique within the scope of the . @@ -38,17 +29,11 @@ namespace Microsoft.Blazor.Rendering /// The assigned identifier for the . protected internal int AssignComponentId(IComponent component) { - lock (_componentStateByComponent) + lock (_componentStateById) { - if (_componentStateByComponent.TryGetValue(component, out _)) - { - throw new ArgumentException("The component was already associated with the renderer."); - } - var componentId = _nextComponentId++; var componentState = new ComponentState(this, componentId, component); _componentStateById.Add(componentId, componentState); - _componentStateByComponent.Add(component, componentState); return componentId; } } @@ -61,13 +46,6 @@ namespace Microsoft.Blazor.Rendering /// The updated render tree to be displayed. internal protected abstract void UpdateDisplay(int componentId, ArraySegment renderTree); - /// - /// Updates the rendered state of the specified . - /// - /// The . - protected void RenderComponent(IComponent component) - => GetRequiredComponentState(component).Render(); - /// /// Updates the rendered state of the specified . /// @@ -88,10 +66,5 @@ namespace Microsoft.Blazor.Rendering => _componentStateById.TryGetValue(componentId, out var componentState) ? componentState : throw new ArgumentException($"The renderer does not have a component with ID {componentId}."); - - private ComponentState GetRequiredComponentState(IComponent component) - => _componentStateByComponent.TryGetValue(component, out var componentState) - ? componentState - : throw new ArgumentException("The component is not associated with the renderer."); } }