Make OpenRegion/CloseRegion not public because they are only to support AddContent(seq, fragment)

This commit is contained in:
Steve Sanderson 2018-02-16 09:22:45 +00:00
parent 41aae0b7e6
commit ad2c63ca37
2 changed files with 13 additions and 20 deletions

View File

@ -201,22 +201,17 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
entry = entry.WithComponentSubtreeLength(_entries.Count - indexOfEntryBeingClosed);
}
/// <summary>
/// Appends a frame denoting the start of a region (that is, a tree fragment that is
/// processed as a unit for the purposes of diffing).
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
public void OpenRegion(int sequence)
// Internal for tests
// Not public because there's no current use case for user code defining regions arbitrarily.
// Currently the sole use case for regions is when appending a RenderFragment.
internal void OpenRegion(int sequence)
{
_openElementIndices.Push(_entries.Count);
Append(RenderTreeFrame.Region(sequence));
}
/// <summary>
/// Marks a previously appended region frame as closed. Calls to this method
/// must be balanced with calls to <see cref="OpenRegion"/>.
/// </summary>
public void CloseRegion()
// See above for why this is not public
internal void CloseRegion()
{
var indexOfEntryBeingClosed = _openElementIndices.Pop();
ref var entry = ref _entries.Buffer[indexOfEntryBeingClosed];

View File

@ -43,22 +43,20 @@ namespace BasicTestApp
private void Render() => _renderHandle.Render(builder =>
{
builder.OpenElement(0, "div"); // Container so we can see that passing through regions is OK
builder.OpenRegion(1);
builder.AddContent(2, "Region will be toggled below ");
builder.AddContent(1, "Region will be toggled below ");
if (_showRegion)
{
builder.AddContent(3, _exampleContent);
builder.AddContent(2, _exampleContent);
}
builder.OpenElement(4, "button");
builder.AddAttribute(5, "onclick", ToggleRegion);
builder.AddContent(6, "Toggle");
builder.OpenElement(3, "button");
builder.AddAttribute(4, "onclick", ToggleRegion);
builder.AddContent(5, "Toggle");
builder.CloseElement();
builder.CloseRegion();
builder.OpenElement(7, "p");
builder.AddContent(8, "The end");
builder.OpenElement(6, "p");
builder.AddContent(7, "The end");
builder.CloseElement();
builder.CloseElement();
});