Remove some implementation code that isn't strictly needed (so far, at least)
This commit is contained in:
parent
04f9c476a8
commit
c95747af3e
|
|
@ -50,7 +50,7 @@ namespace Microsoft.Blazor.Browser.Rendering
|
||||||
componentId);
|
componentId);
|
||||||
_rootComponents.Add(component);
|
_rootComponents.Add(component);
|
||||||
|
|
||||||
RenderComponent(component);
|
RenderComponent(componentId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,6 @@
|
||||||
using Microsoft.Blazor.Components;
|
using Microsoft.Blazor.Components;
|
||||||
using Microsoft.Blazor.RenderTree;
|
using Microsoft.Blazor.RenderTree;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.CompilerServices;
|
|
||||||
|
|
||||||
namespace Microsoft.Blazor.Rendering
|
namespace Microsoft.Blazor.Rendering
|
||||||
{
|
{
|
||||||
|
|
@ -21,15 +19,8 @@ namespace Microsoft.Blazor.Rendering
|
||||||
// these reference descendant components and associated ComponentState instances.
|
// these reference descendant components and associated ComponentState instances.
|
||||||
private readonly WeakValueDictionary<int, ComponentState> _componentStateById
|
private readonly WeakValueDictionary<int, ComponentState> _componentStateById
|
||||||
= new WeakValueDictionary<int, ComponentState>();
|
= new WeakValueDictionary<int, ComponentState>();
|
||||||
private readonly ConditionalWeakTable<IComponent, ComponentState> _componentStateByComponent
|
|
||||||
= new ConditionalWeakTable<IComponent, ComponentState>();
|
|
||||||
private int _nextComponentId = 0; // TODO: change to 'long' when Mono .NET->JS interop supports it
|
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<IComponent> _topLevelComponents = new List<IComponent>();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Associates the <see cref="IComponent"/> with the <see cref="Renderer"/>, assigning
|
/// Associates the <see cref="IComponent"/> with the <see cref="Renderer"/>, assigning
|
||||||
/// an identifier that is unique within the scope of the <see cref="Renderer"/>.
|
/// an identifier that is unique within the scope of the <see cref="Renderer"/>.
|
||||||
|
|
@ -38,17 +29,11 @@ namespace Microsoft.Blazor.Rendering
|
||||||
/// <returns>The assigned identifier for the <see cref="IComponent"/>.</returns>
|
/// <returns>The assigned identifier for the <see cref="IComponent"/>.</returns>
|
||||||
protected internal int AssignComponentId(IComponent component)
|
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 componentId = _nextComponentId++;
|
||||||
var componentState = new ComponentState(this, componentId, component);
|
var componentState = new ComponentState(this, componentId, component);
|
||||||
_componentStateById.Add(componentId, componentState);
|
_componentStateById.Add(componentId, componentState);
|
||||||
_componentStateByComponent.Add(component, componentState);
|
|
||||||
return componentId;
|
return componentId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -61,13 +46,6 @@ namespace Microsoft.Blazor.Rendering
|
||||||
/// <param name="renderTree">The updated render tree to be displayed.</param>
|
/// <param name="renderTree">The updated render tree to be displayed.</param>
|
||||||
internal protected abstract void UpdateDisplay(int componentId, ArraySegment<RenderTreeNode> renderTree);
|
internal protected abstract void UpdateDisplay(int componentId, ArraySegment<RenderTreeNode> renderTree);
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Updates the rendered state of the specified <see cref="IComponent"/>.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="component">The <see cref="IComponent"/>.</param>
|
|
||||||
protected void RenderComponent(IComponent component)
|
|
||||||
=> GetRequiredComponentState(component).Render();
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates the rendered state of the specified <see cref="IComponent"/>.
|
/// Updates the rendered state of the specified <see cref="IComponent"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -88,10 +66,5 @@ namespace Microsoft.Blazor.Rendering
|
||||||
=> _componentStateById.TryGetValue(componentId, out var componentState)
|
=> _componentStateById.TryGetValue(componentId, out var componentState)
|
||||||
? componentState
|
? componentState
|
||||||
: throw new ArgumentException($"The renderer does not have a component with ID {componentId}.");
|
: 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.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue