// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using Microsoft.AspNetCore.Blazor.RenderTree;
namespace Microsoft.AspNetCore.Blazor.Rendering
{
///
/// Collects the data produced by the rendering system during the course
/// of rendering a single batch. This tracks both the final output data
/// and the intermediate states (such as the queue of components still to
/// be rendered).
///
internal class RenderBatchBuilder
{
// Primary result data
public ArrayBuilder UpdatedComponentDiffs { get; } = new ArrayBuilder();
public ArrayBuilder DisposedComponentIds { get; } = new ArrayBuilder();
public ArrayBuilder DisposedEventHandlerIds { get; } = new ArrayBuilder();
// Buffers referenced by UpdatedComponentDiffs
public ArrayBuilder EditsBuffer { get; } = new ArrayBuilder();
public ArrayBuilder ReferenceFramesBuffer { get; } = new ArrayBuilder();
// State of render pipeline
public Queue ComponentRenderQueue { get; } = new Queue();
public Queue ComponentDisposalQueue { get; } = new Queue();
// Scratch data structure for understanding attribute diffs.
public Dictionary AttributeDiffSet { get; } = new Dictionary();
public void Clear()
{
EditsBuffer.Clear();
ReferenceFramesBuffer.Clear();
ComponentRenderQueue.Clear();
UpdatedComponentDiffs.Clear();
DisposedComponentIds.Clear();
DisposedEventHandlerIds.Clear();
AttributeDiffSet.Clear();
}
public RenderBatch ToBatch()
=> new RenderBatch(
UpdatedComponentDiffs.ToRange(),
ReferenceFramesBuffer.ToRange(),
DisposedComponentIds.ToRange());
}
}