Rename RenderTreeNode -> RenderTreeFrame (and correspondingly, "node" ->

"frame" everywhere)
This commit is contained in:
Steve Sanderson 2018-02-04 21:54:37 +00:00
parent 4526c8c1f0
commit f1332919bc
28 changed files with 619 additions and 621 deletions

View File

@ -1,6 +1,6 @@
import { System_Array, MethodHandle } from '../Platform/Platform'; import { System_Array, MethodHandle } from '../Platform/Platform';
import { getRenderTreeEditPtr, renderTreeEdit, RenderTreeEditPointer, EditType } from './RenderTreeEdit'; import { getRenderTreeEditPtr, renderTreeEdit, RenderTreeEditPointer, EditType } from './RenderTreeEdit';
import { getTreeNodePtr, renderTreeNode, NodeType, RenderTreeNodePointer } from './RenderTreeNode'; import { getTreeFramePtr, renderTreeFrame, FrameType, RenderTreeFramePointer } from './RenderTreeFrame';
import { platform } from '../Environment'; import { platform } from '../Environment';
let raiseEventMethod: MethodHandle; let raiseEventMethod: MethodHandle;
let renderComponentMethod: MethodHandle; let renderComponentMethod: MethodHandle;
@ -15,7 +15,7 @@ export class BrowserRenderer {
this.childComponentLocations[componentId] = element; this.childComponentLocations[componentId] = element;
} }
public updateComponent(componentId: number, edits: System_Array<RenderTreeEditPointer>, editsLength: number, referenceTree: System_Array<RenderTreeNodePointer>) { public updateComponent(componentId: number, edits: System_Array<RenderTreeEditPointer>, editsLength: number, referenceTree: System_Array<RenderTreeFramePointer>) {
const element = this.childComponentLocations[componentId]; const element = this.childComponentLocations[componentId];
if (!element) { if (!element) {
throw new Error(`No element is currently associated with component ${componentId}`); throw new Error(`No element is currently associated with component ${componentId}`);
@ -28,31 +28,31 @@ export class BrowserRenderer {
delete this.childComponentLocations[componentId]; delete this.childComponentLocations[componentId];
} }
applyEdits(componentId: number, parent: Element, childIndex: number, edits: System_Array<RenderTreeEditPointer>, editsLength: number, referenceTree: System_Array<RenderTreeNodePointer>) { applyEdits(componentId: number, parent: Element, childIndex: number, edits: System_Array<RenderTreeEditPointer>, editsLength: number, referenceTree: System_Array<RenderTreeFramePointer>) {
let currentDepth = 0; let currentDepth = 0;
let childIndexAtCurrentDepth = childIndex; let childIndexAtCurrentDepth = childIndex;
for (let editIndex = 0; editIndex < editsLength; editIndex++) { for (let editIndex = 0; editIndex < editsLength; editIndex++) {
const edit = getRenderTreeEditPtr(edits, editIndex); const edit = getRenderTreeEditPtr(edits, editIndex);
const editType = renderTreeEdit.type(edit); const editType = renderTreeEdit.type(edit);
switch (editType) { switch (editType) {
case EditType.prependNode: { case EditType.prependFrame: {
const nodeIndex = renderTreeEdit.newTreeIndex(edit); const frameIndex = renderTreeEdit.newTreeIndex(edit);
const node = getTreeNodePtr(referenceTree, nodeIndex); const frame = getTreeFramePtr(referenceTree, frameIndex);
const siblingIndex = renderTreeEdit.siblingIndex(edit); const siblingIndex = renderTreeEdit.siblingIndex(edit);
this.insertNode(componentId, parent, childIndexAtCurrentDepth + siblingIndex, referenceTree, node, nodeIndex); this.insertFrame(componentId, parent, childIndexAtCurrentDepth + siblingIndex, referenceTree, frame, frameIndex);
break; break;
} }
case EditType.removeNode: { case EditType.removeFrame: {
const siblingIndex = renderTreeEdit.siblingIndex(edit); const siblingIndex = renderTreeEdit.siblingIndex(edit);
removeNodeFromDOM(parent, childIndexAtCurrentDepth + siblingIndex); removeNodeFromDOM(parent, childIndexAtCurrentDepth + siblingIndex);
break; break;
} }
case EditType.setAttribute: { case EditType.setAttribute: {
const nodeIndex = renderTreeEdit.newTreeIndex(edit); const frameIndex = renderTreeEdit.newTreeIndex(edit);
const node = getTreeNodePtr(referenceTree, nodeIndex); const frame = getTreeFramePtr(referenceTree, frameIndex);
const siblingIndex = renderTreeEdit.siblingIndex(edit); const siblingIndex = renderTreeEdit.siblingIndex(edit);
const element = parent.childNodes[childIndexAtCurrentDepth + siblingIndex] as HTMLElement; const element = parent.childNodes[childIndexAtCurrentDepth + siblingIndex] as HTMLElement;
this.applyAttribute(componentId, element, node, nodeIndex); this.applyAttribute(componentId, element, frame, frameIndex);
break; break;
} }
case EditType.removeAttribute: { case EditType.removeAttribute: {
@ -61,11 +61,11 @@ export class BrowserRenderer {
break; break;
} }
case EditType.updateText: { case EditType.updateText: {
const nodeIndex = renderTreeEdit.newTreeIndex(edit); const frameIndex = renderTreeEdit.newTreeIndex(edit);
const node = getTreeNodePtr(referenceTree, nodeIndex); const frame = getTreeFramePtr(referenceTree, frameIndex);
const siblingIndex = renderTreeEdit.siblingIndex(edit); const siblingIndex = renderTreeEdit.siblingIndex(edit);
const domTextNode = parent.childNodes[childIndexAtCurrentDepth + siblingIndex] as Text; const domTextNode = parent.childNodes[childIndexAtCurrentDepth + siblingIndex] as Text;
domTextNode.textContent = renderTreeNode.textContent(node); domTextNode.textContent = renderTreeFrame.textContent(frame);
break; break;
} }
case EditType.stepIn: { case EditType.stepIn: {
@ -89,79 +89,79 @@ export class BrowserRenderer {
} }
} }
insertNode(componentId: number, parent: Element, childIndex: number, nodes: System_Array<RenderTreeNodePointer>, node: RenderTreeNodePointer, nodeIndex: number) { insertFrame(componentId: number, parent: Element, childIndex: number, frames: System_Array<RenderTreeFramePointer>, frame: RenderTreeFramePointer, frameIndex: number) {
const nodeType = renderTreeNode.nodeType(node); const frameType = renderTreeFrame.frameType(frame);
switch (nodeType) { switch (frameType) {
case NodeType.element: case FrameType.element:
this.insertElement(componentId, parent, childIndex, nodes, node, nodeIndex); this.insertElement(componentId, parent, childIndex, frames, frame, frameIndex);
break; break;
case NodeType.text: case FrameType.text:
this.insertText(parent, childIndex, node); this.insertText(parent, childIndex, frame);
break; break;
case NodeType.attribute: case FrameType.attribute:
throw new Error('Attribute nodes should only be present as leading children of element nodes.'); throw new Error('Attribute frames should only be present as leading children of element frames.');
case NodeType.component: case FrameType.component:
this.insertComponent(parent, childIndex, node); this.insertComponent(parent, childIndex, frame);
break; break;
default: default:
const unknownType: never = nodeType; // Compile-time verification that the switch was exhaustive const unknownType: never = frameType; // Compile-time verification that the switch was exhaustive
throw new Error(`Unknown node type: ${unknownType}`); throw new Error(`Unknown frame type: ${unknownType}`);
} }
} }
insertElement(componentId: number, parent: Element, childIndex: number, nodes: System_Array<RenderTreeNodePointer>, node: RenderTreeNodePointer, nodeIndex: number) { insertElement(componentId: number, parent: Element, childIndex: number, frames: System_Array<RenderTreeFramePointer>, frame: RenderTreeFramePointer, frameIndex: number) {
const tagName = renderTreeNode.elementName(node)!; const tagName = renderTreeFrame.elementName(frame)!;
const newDomElement = document.createElement(tagName); const newDomElement = document.createElement(tagName);
insertNodeIntoDOM(newDomElement, parent, childIndex); insertNodeIntoDOM(newDomElement, parent, childIndex);
// Apply attributes // Apply attributes
const descendantsEndIndex = renderTreeNode.descendantsEndIndex(node); const descendantsEndIndex = renderTreeFrame.descendantsEndIndex(frame);
for (let descendantIndex = nodeIndex + 1; descendantIndex <= descendantsEndIndex; descendantIndex++) { for (let descendantIndex = frameIndex + 1; descendantIndex <= descendantsEndIndex; descendantIndex++) {
const descendantNode = getTreeNodePtr(nodes, descendantIndex); const descendantFrame = getTreeFramePtr(frames, descendantIndex);
if (renderTreeNode.nodeType(descendantNode) === NodeType.attribute) { if (renderTreeFrame.frameType(descendantFrame) === FrameType.attribute) {
this.applyAttribute(componentId, newDomElement, descendantNode, descendantIndex); this.applyAttribute(componentId, newDomElement, descendantFrame, descendantIndex);
} else { } else {
// As soon as we see a non-attribute child, all the subsequent child nodes are // As soon as we see a non-attribute child, all the subsequent child frames are
// not attributes, so bail out and insert the remnants recursively // not attributes, so bail out and insert the remnants recursively
this.insertNodeRange(componentId, newDomElement, 0, nodes, descendantIndex, descendantsEndIndex); this.insertFrameRange(componentId, newDomElement, 0, frames, descendantIndex, descendantsEndIndex);
break; break;
} }
} }
} }
insertComponent(parent: Element, childIndex: number, node: RenderTreeNodePointer) { insertComponent(parent: Element, childIndex: number, frame: RenderTreeFramePointer) {
// Currently, to support O(1) lookups from render tree nodes to DOM nodes, we rely on // Currently, to support O(1) lookups from render tree frames to DOM nodes, we rely on
// each child component existing as a single top-level element in the DOM. To guarantee // each child component existing as a single top-level element in the DOM. To guarantee
// that, we wrap child components in these 'blazor-component' wrappers. // that, we wrap child components in these 'blazor-component' wrappers.
// To improve on this in the future: // To improve on this in the future:
// - If we can statically detect that a given component always produces a single top-level // - If we can statically detect that a given component always produces a single top-level
// element anyway, then don't wrap it in a further nonstandard element // element anyway, then don't wrap it in a further nonstandard element
// - If we really want to support child components producing multiple top-level nodes and // - If we really want to support child components producing multiple top-level frames and
// not being wrapped in a container at all, then every time a component is refreshed in // not being wrapped in a container at all, then every time a component is refreshed in
// the DOM, we could update an array on the parent element that specifies how many DOM // the DOM, we could update an array on the parent element that specifies how many DOM
// nodes correspond to each of its render tree nodes. Then when that parent wants to // nodes correspond to each of its render tree frames. Then when that parent wants to
// locate the first DOM node for a render tree node, it can sum all the node counts for // locate the first DOM node for a render tree frame, it can sum all the frame counts for
// all the preceding render trees nodes. It's O(N), but where N is the number of siblings // all the preceding render trees frames. It's O(N), but where N is the number of siblings
// (counting child components as a single item), so N will rarely if ever be large. // (counting child components as a single item), so N will rarely if ever be large.
// We could even keep track of whether all the child components happen to have exactly 1 // We could even keep track of whether all the child components happen to have exactly 1
// top level node, and in that case, there's no need to sum as we can do direct lookups. // top level frames, and in that case, there's no need to sum as we can do direct lookups.
const containerElement = document.createElement('blazor-component'); const containerElement = document.createElement('blazor-component');
insertNodeIntoDOM(containerElement, parent, childIndex); insertNodeIntoDOM(containerElement, parent, childIndex);
// All we have to do is associate the child component ID with its location. We don't actually // All we have to do is associate the child component ID with its location. We don't actually
// do any rendering here, because the diff for the child will appear later in the render batch. // do any rendering here, because the diff for the child will appear later in the render batch.
const childComponentId = renderTreeNode.componentId(node); const childComponentId = renderTreeFrame.componentId(frame);
this.attachComponentToElement(childComponentId, containerElement); this.attachComponentToElement(childComponentId, containerElement);
} }
insertText(parent: Element, childIndex: number, textNode: RenderTreeNodePointer) { insertText(parent: Element, childIndex: number, textFrame: RenderTreeFramePointer) {
const textContent = renderTreeNode.textContent(textNode)!; const textContent = renderTreeFrame.textContent(textFrame)!;
const newDomTextNode = document.createTextNode(textContent); const newDomTextNode = document.createTextNode(textContent);
insertNodeIntoDOM(newDomTextNode, parent, childIndex); insertNodeIntoDOM(newDomTextNode, parent, childIndex);
} }
applyAttribute(componentId: number, toDomElement: Element, attributeNode: RenderTreeNodePointer, attributeNodeIndex: number) { applyAttribute(componentId: number, toDomElement: Element, attributeFrame: RenderTreeFramePointer, attributeFrameIndex: number) {
const attributeName = renderTreeNode.attributeName(attributeNode)!; const attributeName = renderTreeFrame.attributeName(attributeFrame)!;
const browserRendererId = this.browserRendererId; const browserRendererId = this.browserRendererId;
// TODO: Instead of applying separate event listeners to each DOM element, use event delegation // TODO: Instead of applying separate event listeners to each DOM element, use event delegation
@ -169,7 +169,7 @@ export class BrowserRenderer {
switch (attributeName) { switch (attributeName) {
case 'onclick': { case 'onclick': {
toDomElement.removeEventListener('click', toDomElement['_blazorClickListener']); toDomElement.removeEventListener('click', toDomElement['_blazorClickListener']);
const listener = () => raiseEvent(browserRendererId, componentId, attributeNodeIndex, 'mouse', { Type: 'click' }); const listener = () => raiseEvent(browserRendererId, componentId, attributeFrameIndex, 'mouse', { Type: 'click' });
toDomElement['_blazorClickListener'] = listener; toDomElement['_blazorClickListener'] = listener;
toDomElement.addEventListener('click', listener); toDomElement.addEventListener('click', listener);
break; break;
@ -181,7 +181,7 @@ export class BrowserRenderer {
// just to establish that we can pass parameters when raising events. // just to establish that we can pass parameters when raising events.
// We use C#-style PascalCase on the eventInfo to simplify deserialization, but this could // We use C#-style PascalCase on the eventInfo to simplify deserialization, but this could
// change if we introduced a richer JSON library on the .NET side. // change if we introduced a richer JSON library on the .NET side.
raiseEvent(browserRendererId, componentId, attributeNodeIndex, 'keyboard', { Type: evt.type, Key: (evt as any).key }); raiseEvent(browserRendererId, componentId, attributeFrameIndex, 'keyboard', { Type: evt.type, Key: (evt as any).key });
}; };
toDomElement['_blazorKeypressListener'] = listener; toDomElement['_blazorKeypressListener'] = listener;
toDomElement.addEventListener('keypress', listener); toDomElement.addEventListener('keypress', listener);
@ -191,20 +191,20 @@ export class BrowserRenderer {
// Treat as a regular string-valued attribute // Treat as a regular string-valued attribute
toDomElement.setAttribute( toDomElement.setAttribute(
attributeName, attributeName,
renderTreeNode.attributeValue(attributeNode)! renderTreeFrame.attributeValue(attributeFrame)!
); );
break; break;
} }
} }
insertNodeRange(componentId: number, parent: Element, childIndex: number, nodes: System_Array<RenderTreeNodePointer>, startIndex: number, endIndex: number) { insertFrameRange(componentId: number, parent: Element, childIndex: number, frames: System_Array<RenderTreeFramePointer>, startIndex: number, endIndex: number) {
for (let index = startIndex; index <= endIndex; index++) { for (let index = startIndex; index <= endIndex; index++) {
const node = getTreeNodePtr(nodes, index); const frame = getTreeFramePtr(frames, index);
this.insertNode(componentId, parent, childIndex, nodes, node, index); this.insertFrame(componentId, parent, childIndex, frames, frame, index);
childIndex++; childIndex++;
// Skip over any descendants, since they are already dealt with recursively // Skip over any descendants, since they are already dealt with recursively
const descendantsEndIndex = renderTreeNode.descendantsEndIndex(node); const descendantsEndIndex = renderTreeFrame.descendantsEndIndex(frame);
if (descendantsEndIndex > 0) { if (descendantsEndIndex > 0) {
index = descendantsEndIndex; index = descendantsEndIndex;
} }
@ -229,7 +229,7 @@ function removeAttributeFromDOM(parent: Element, childIndex: number, attributeNa
element.removeAttribute(attributeName); element.removeAttribute(attributeName);
} }
function raiseEvent(browserRendererId: number, componentId: number, renderTreeNodeIndex: number, eventInfoType: EventInfoType, eventInfo: any) { function raiseEvent(browserRendererId: number, componentId: number, renderTreeFrameIndex: number, eventInfoType: EventInfoType, eventInfo: any) {
if (!raiseEventMethod) { if (!raiseEventMethod) {
raiseEventMethod = platform.findMethod( raiseEventMethod = platform.findMethod(
'Microsoft.AspNetCore.Blazor.Browser', 'Microsoft.AspNetCore.Blazor.Browser.Rendering', 'BrowserRendererEventDispatcher', 'DispatchEvent' 'Microsoft.AspNetCore.Blazor.Browser', 'Microsoft.AspNetCore.Blazor.Browser.Rendering', 'BrowserRendererEventDispatcher', 'DispatchEvent'
@ -239,7 +239,7 @@ function raiseEvent(browserRendererId: number, componentId: number, renderTreeNo
const eventDescriptor = { const eventDescriptor = {
BrowserRendererId: browserRendererId, BrowserRendererId: browserRendererId,
ComponentId: componentId, ComponentId: componentId,
RenderTreeNodeIndex: renderTreeNodeIndex, RenderTreeFrameIndex: renderTreeFrameIndex,
EventArgsType: eventInfoType EventArgsType: eventInfoType
}; };

View File

@ -1,6 +1,6 @@
import { Pointer, System_Array } from '../Platform/Platform'; import { Pointer, System_Array } from '../Platform/Platform';
import { platform } from '../Environment'; import { platform } from '../Environment';
import { RenderTreeNodePointer } from './RenderTreeNode'; import { RenderTreeFramePointer } from './RenderTreeFrame';
import { RenderTreeEditPointer } from './RenderTreeEdit'; import { RenderTreeEditPointer } from './RenderTreeEdit';
// Keep in sync with the structs in .NET code // Keep in sync with the structs in .NET code
@ -20,7 +20,7 @@ export const renderTreeDiffStructLength = 4 + 2 * arrayRangeStructLength;
export const renderTreeDiff = { export const renderTreeDiff = {
componentId: (obj: RenderTreeDiffPointer) => platform.readInt32Field(obj, 0), componentId: (obj: RenderTreeDiffPointer) => platform.readInt32Field(obj, 0),
edits: (obj: RenderTreeDiffPointer) => platform.readStructField<ArrayRangePointer<RenderTreeEditPointer>>(obj, 4), edits: (obj: RenderTreeDiffPointer) => platform.readStructField<ArrayRangePointer<RenderTreeEditPointer>>(obj, 4),
currentState: (obj: RenderTreeDiffPointer) => platform.readStructField<ArrayRangePointer<RenderTreeNodePointer>>(obj, 4 + arrayRangeStructLength), currentState: (obj: RenderTreeDiffPointer) => platform.readStructField<ArrayRangePointer<RenderTreeFramePointer>>(obj, 4 + arrayRangeStructLength),
}; };
// Nominal types to ensure only valid pointers are passed to the functions above. // Nominal types to ensure only valid pointers are passed to the functions above.

View File

@ -15,8 +15,8 @@ export const renderTreeEdit = {
}; };
export enum EditType { export enum EditType {
prependNode = 1, prependFrame = 1,
removeNode = 2, removeFrame = 2,
setAttribute = 3, setAttribute = 3,
removeAttribute = 4, removeAttribute = 4,
updateText = 5, updateText = 5,

View File

@ -0,0 +1,34 @@
import { System_String, System_Array, Pointer } from '../Platform/Platform';
import { platform } from '../Environment';
const renderTreeFrameStructLength = 40;
// To minimise GC pressure, instead of instantiating a JS object to represent each tree frame,
// we work in terms of pointers to the structs on the .NET heap, and use static functions that
// know how to read property values from those structs.
export function getTreeFramePtr(renderTreeEntries: System_Array<RenderTreeFramePointer>, index: number) {
return platform.getArrayEntryPtr(renderTreeEntries, index, renderTreeFrameStructLength);
}
export const renderTreeFrame = {
// The properties and memory layout must be kept in sync with the .NET equivalent in RenderTreeFrame.cs
frameType: (frame: RenderTreeFramePointer) => platform.readInt32Field(frame, 4) as FrameType,
elementName: (frame: RenderTreeFramePointer) => platform.readStringField(frame, 8),
descendantsEndIndex: (frame: RenderTreeFramePointer) => platform.readInt32Field(frame, 12) as FrameType,
textContent: (frame: RenderTreeFramePointer) => platform.readStringField(frame, 16),
attributeName: (frame: RenderTreeFramePointer) => platform.readStringField(frame, 20),
attributeValue: (frame: RenderTreeFramePointer) => platform.readStringField(frame, 24),
componentId: (frame: RenderTreeFramePointer) => platform.readInt32Field(frame, 32),
};
export enum FrameType {
// The values must be kept in sync with the .NET equivalent in RenderTreeFrameType.cs
element = 1,
text = 2,
attribute = 3,
component = 4,
}
// Nominal type to ensure only valid pointers are passed to the renderTreeFrame functions.
// At runtime the values are just numbers.
export interface RenderTreeFramePointer extends Pointer { RenderTreeFramePointer__DO_NOT_IMPLEMENT: any }

View File

@ -1,34 +0,0 @@
import { System_String, System_Array, Pointer } from '../Platform/Platform';
import { platform } from '../Environment';
const renderTreeNodeStructLength = 40;
// To minimise GC pressure, instead of instantiating a JS object to represent each tree node,
// we work in terms of pointers to the structs on the .NET heap, and use static functions that
// know how to read property values from those structs.
export function getTreeNodePtr(renderTreeEntries: System_Array<RenderTreeNodePointer>, index: number) {
return platform.getArrayEntryPtr(renderTreeEntries, index, renderTreeNodeStructLength);
}
export const renderTreeNode = {
// The properties and memory layout must be kept in sync with the .NET equivalent in RenderTreeNode.cs
nodeType: (node: RenderTreeNodePointer) => platform.readInt32Field(node, 4) as NodeType,
elementName: (node: RenderTreeNodePointer) => platform.readStringField(node, 8),
descendantsEndIndex: (node: RenderTreeNodePointer) => platform.readInt32Field(node, 12) as NodeType,
textContent: (node: RenderTreeNodePointer) => platform.readStringField(node, 16),
attributeName: (node: RenderTreeNodePointer) => platform.readStringField(node, 20),
attributeValue: (node: RenderTreeNodePointer) => platform.readStringField(node, 24),
componentId: (node: RenderTreeNodePointer) => platform.readInt32Field(node, 32),
};
export enum NodeType {
// The values must be kept in sync with the .NET equivalent in RenderTreeNodeType.cs
element = 1,
text = 2,
attribute = 3,
component = 4,
}
// Nominal type to ensure only valid pointers are passed to the renderTreeNode functions.
// At runtime the values are just numbers.
export interface RenderTreeNodePointer extends Pointer { RenderTreeNodePointer__DO_NOT_IMPLEMENT: any }

View File

@ -1,7 +1,5 @@
import { System_Object, System_String, System_Array, MethodHandle, Pointer } from '../Platform/Platform'; import { System_Object, System_String, System_Array, MethodHandle, Pointer } from '../Platform/Platform';
import { platform } from '../Environment'; import { platform } from '../Environment';
import { getTreeNodePtr, renderTreeNode, NodeType, RenderTreeNodePointer } from './RenderTreeNode';
import { RenderTreeEditPointer } from './RenderTreeEdit';
import { renderBatch as renderBatchStruct, arrayRange, renderTreeDiffStructLength, renderTreeDiff, RenderBatchPointer, RenderTreeDiffPointer } from './RenderBatch'; import { renderBatch as renderBatchStruct, arrayRange, renderTreeDiffStructLength, renderTreeDiff, RenderBatchPointer, RenderTreeDiffPointer } from './RenderBatch';
import { BrowserRenderer } from './BrowserRenderer'; import { BrowserRenderer } from './BrowserRenderer';

View File

@ -24,7 +24,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Rendering
var browserRenderer = BrowserRendererRegistry.Find(eventDescriptor.BrowserRendererId); var browserRenderer = BrowserRendererRegistry.Find(eventDescriptor.BrowserRendererId);
browserRenderer.DispatchBrowserEvent( browserRenderer.DispatchBrowserEvent(
eventDescriptor.ComponentId, eventDescriptor.ComponentId,
eventDescriptor.RenderTreeNodeIndex, eventDescriptor.RenderTreeFrameIndex,
eventArgs); eventArgs);
} }
@ -45,7 +45,7 @@ namespace Microsoft.AspNetCore.Blazor.Browser.Rendering
{ {
public int BrowserRendererId { get; set; } public int BrowserRendererId { get; set; }
public int ComponentId { get; set; } public int ComponentId { get; set; }
public int RenderTreeNodeIndex { get; set; } public int RenderTreeFrameIndex { get; set; }
public string EventArgsType { get; set; } public string EventArgsType { get; set; }
} }
} }

View File

@ -106,7 +106,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Core.RazorCompilation.Engine
// To support syntax like <elem @completeAttributePair /> (which in turn supports syntax // To support syntax like <elem @completeAttributePair /> (which in turn supports syntax
// like <elem @OnSomeEvent(Handler) />), check whether we are currently in the middle of // like <elem @OnSomeEvent(Handler) />), check whether we are currently in the middle of
// writing an element. If so, treat this C# expression as something that should evaluate // writing an element. If so, treat this C# expression as something that should evaluate
// as a RenderTreeNode of type Attribute. // as a RenderTreeFrame of type Attribute.
if (_unconsumedHtml != null) if (_unconsumedHtml != null)
{ {
var token = (IntermediateToken)node.Children.Single(); var token = (IntermediateToken)node.Children.Single();
@ -197,7 +197,7 @@ namespace Microsoft.AspNetCore.Blazor.Build.Core.RazorCompilation.Engine
var codeWriter = context.CodeWriter; var codeWriter = context.CodeWriter;
// TODO: As an optimization, identify static subtrees (i.e., HTML elements in the Razor source // TODO: As an optimization, identify static subtrees (i.e., HTML elements in the Razor source
// that contain no C#) and represent them as a new RenderTreeNodeType called StaticElement or // that contain no C#) and represent them as a new RenderTreeFrameType called StaticElement or
// similar. This means you can have arbitrarily deep static subtrees without paying any per- // similar. This means you can have arbitrarily deep static subtrees without paying any per-
// node cost during rendering or diffing. // node cost during rendering or diffing.
HtmlToken nextToken; HtmlToken nextToken;

View File

@ -44,9 +44,9 @@ namespace Microsoft.AspNetCore.Blazor.Components
/// Handles click events by invoking <paramref name="handler"/>. /// Handles click events by invoking <paramref name="handler"/>.
/// </summary> /// </summary>
/// <param name="handler">The handler to be invoked when the event occurs.</param> /// <param name="handler">The handler to be invoked when the event occurs.</param>
/// <returns>A <see cref="RenderTreeNode"/> that represents the event handler.</returns> /// <returns>A <see cref="RenderTreeFrame"/> that represents the event handler.</returns>
protected RenderTreeNode onclick(Action handler) protected RenderTreeFrame onclick(Action handler)
// Note that the 'sequence' value is updated later when inserted into the tree // Note that the 'sequence' value is updated later when inserted into the tree
=> RenderTreeNode.Attribute(0, "onclick", _ => handler()); => RenderTreeFrame.Attribute(0, "onclick", _ => handler());
} }
} }

View File

@ -13,7 +13,7 @@ namespace Microsoft.AspNetCore.Blazor.Components
/// <summary> /// <summary>
/// Builds a <see cref="RenderTree"/> representing the current state of the component. /// Builds a <see cref="RenderTree"/> representing the current state of the component.
/// </summary> /// </summary>
/// <param name="builder">A <see cref="RenderTreeBuilder"/> to which the rendered nodes should be appended.</param> /// <param name="builder">A <see cref="RenderTreeBuilder"/> to which the rendered frames should be appended.</param>
void BuildRenderTree(RenderTreeBuilder builder); void BuildRenderTree(RenderTreeBuilder builder);
} }
} }

View File

@ -9,14 +9,14 @@ using System.Collections.Generic;
namespace Microsoft.AspNetCore.Blazor.RenderTree namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
/// <summary> /// <summary>
/// Provides methods for building a collection of <see cref="RenderTreeNode"/> entries. /// Provides methods for building a collection of <see cref="RenderTreeFrame"/> entries.
/// </summary> /// </summary>
public class RenderTreeBuilder public class RenderTreeBuilder
{ {
private readonly Renderer _renderer; private readonly Renderer _renderer;
private readonly ArrayBuilder<RenderTreeNode> _entries = new ArrayBuilder<RenderTreeNode>(10); private readonly ArrayBuilder<RenderTreeFrame> _entries = new ArrayBuilder<RenderTreeFrame>(10);
private readonly Stack<int> _openElementIndices = new Stack<int>(); private readonly Stack<int> _openElementIndices = new Stack<int>();
private RenderTreeNodeType? _lastNonAttributeNodeType; private RenderTreeFrameType? _lastNonAttributeFrameType;
/// <summary> /// <summary>
/// Constructs an instance of <see cref="RenderTreeBuilder"/>. /// Constructs an instance of <see cref="RenderTreeBuilder"/>.
@ -28,21 +28,21 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
} }
/// <summary> /// <summary>
/// Appends a node representing an element, i.e., a container for other nodes. /// Appends a frame representing an element, i.e., a container for other frames.
/// In order for the <see cref="RenderTreeBuilder"/> state to be valid, you must /// In order for the <see cref="RenderTreeBuilder"/> state to be valid, you must
/// also call <see cref="CloseElement"/> immediately after appending the /// also call <see cref="CloseElement"/> immediately after appending the
/// new element's child nodes. /// new element's child frames.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="elementName">A value representing the type of the element.</param> /// <param name="elementName">A value representing the type of the element.</param>
public void OpenElement(int sequence, string elementName) public void OpenElement(int sequence, string elementName)
{ {
_openElementIndices.Push(_entries.Count); _openElementIndices.Push(_entries.Count);
Append(RenderTreeNode.Element(sequence, elementName)); Append(RenderTreeFrame.Element(sequence, elementName));
} }
/// <summary> /// <summary>
/// Marks a previously appended element node as closed. Calls to this method /// Marks a previously appended element frame as closed. Calls to this method
/// must be balanced with calls to <see cref="OpenElement(string)"/>. /// must be balanced with calls to <see cref="OpenElement(string)"/>.
/// </summary> /// </summary>
public void CloseElement() public void CloseElement()
@ -52,23 +52,23 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
} }
/// <summary> /// <summary>
/// Appends a node representing text content. /// Appends a frame representing text content.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="textContent">Content for the new text node.</param> /// <param name="textContent">Content for the new text frame.</param>
public void AddText(int sequence, string textContent) public void AddText(int sequence, string textContent)
=> Append(RenderTreeNode.Text(sequence, textContent)); => Append(RenderTreeFrame.Text(sequence, textContent));
/// <summary> /// <summary>
/// Appends a node representing text content. /// Appends a frame representing text content.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="textContent">Content for the new text node.</param> /// <param name="textContent">Content for the new text frame.</param>
public void AddText(int sequence, object textContent) public void AddText(int sequence, object textContent)
=> AddText(sequence, textContent?.ToString()); => AddText(sequence, textContent?.ToString());
/// <summary> /// <summary>
/// Appends a node representing a string-valued attribute. /// Appends a frame representing a string-valued attribute.
/// The attribute is associated with the most recently added element. /// The attribute is associated with the most recently added element.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
@ -77,11 +77,11 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
public void AddAttribute(int sequence, string name, string value) public void AddAttribute(int sequence, string name, string value)
{ {
AssertCanAddAttribute(); AssertCanAddAttribute();
Append(RenderTreeNode.Attribute(sequence, name, value)); Append(RenderTreeFrame.Attribute(sequence, name, value));
} }
/// <summary> /// <summary>
/// Appends a node representing an <see cref="UIEventArgs"/>-valued attribute. /// Appends a frame representing an <see cref="UIEventArgs"/>-valued attribute.
/// The attribute is associated with the most recently added element. /// The attribute is associated with the most recently added element.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
@ -90,11 +90,11 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
public void AddAttribute(int sequence, string name, UIEventHandler value) public void AddAttribute(int sequence, string name, UIEventHandler value)
{ {
AssertCanAddAttribute(); AssertCanAddAttribute();
Append(RenderTreeNode.Attribute(sequence, name, value)); Append(RenderTreeFrame.Attribute(sequence, name, value));
} }
/// <summary> /// <summary>
/// Appends a node representing a string-valued attribute. /// Appends a frame representing a string-valued attribute.
/// The attribute is associated with the most recently added element. /// The attribute is associated with the most recently added element.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
@ -102,14 +102,14 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// <param name="value">The value of the attribute.</param> /// <param name="value">The value of the attribute.</param>
public void AddAttribute(int sequence, string name, object value) public void AddAttribute(int sequence, string name, object value)
{ {
if (_lastNonAttributeNodeType == RenderTreeNodeType.Element) if (_lastNonAttributeFrameType == RenderTreeFrameType.Element)
{ {
// Element attribute values can only be strings or UIEventHandler // Element attribute values can only be strings or UIEventHandler
Append(RenderTreeNode.Attribute(sequence, name, value.ToString())); Append(RenderTreeFrame.Attribute(sequence, name, value.ToString()));
} }
else if (_lastNonAttributeNodeType == RenderTreeNodeType.Component) else if (_lastNonAttributeFrameType == RenderTreeFrameType.Component)
{ {
Append(RenderTreeNode.Attribute(sequence, name, value)); Append(RenderTreeFrame.Attribute(sequence, name, value));
} }
else else
{ {
@ -119,26 +119,26 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
} }
/// <summary> /// <summary>
/// Appends a node representing an attribute. /// Appends a frame representing an attribute.
/// The attribute is associated with the most recently added element. /// The attribute is associated with the most recently added element.
/// </summary> /// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="name">The name of the attribute.</param> /// <param name="name">The name of the attribute.</param>
/// <param name="value">The value of the attribute.</param> /// <param name="value">The value of the attribute.</param>
public void AddAttribute(int sequence, RenderTreeNode node) public void AddAttribute(int sequence, RenderTreeFrame frame)
{ {
if (node.NodeType != RenderTreeNodeType.Attribute) if (frame.FrameType != RenderTreeFrameType.Attribute)
{ {
throw new ArgumentException($"The {nameof(node.NodeType)} must be {RenderTreeNodeType.Attribute}."); throw new ArgumentException($"The {nameof(frame.FrameType)} must be {RenderTreeFrameType.Attribute}.");
} }
AssertCanAddAttribute(); AssertCanAddAttribute();
node.SetSequence(sequence); frame.SetSequence(sequence);
Append(node); Append(frame);
} }
/// <summary> /// <summary>
/// Appends a node representing a child component. /// Appends a frame representing a child component.
/// </summary> /// </summary>
/// <typeparam name="TComponent">The type of the child component.</typeparam> /// <typeparam name="TComponent">The type of the child component.</typeparam>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param> /// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
@ -146,21 +146,21 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
// Currently, child components can't have further grandchildren of their own, so it would // Currently, child components can't have further grandchildren of their own, so it would
// technically be possible to skip their CloseElement calls and not track them in _openElementIndices. // technically be possible to skip their CloseElement calls and not track them in _openElementIndices.
// However at some point we might want to have the grandchildren nodes available at runtime // However at some point we might want to have the grandchildren frames available at runtime
// (rather than being parsed as attributes at compile time) so that we could have APIs for // (rather than being parsed as attributes at compile time) so that we could have APIs for
// components to query the complete hierarchy of transcluded nodes instead of forcing the // components to query the complete hierarchy of transcluded frames instead of forcing the
// transcluded subtree to be in a particular shape such as representing key/value pairs. // transcluded subtree to be in a particular shape such as representing key/value pairs.
// So it's more flexible if we track open/close nodes for components explicitly. // So it's more flexible if we track open/close frames for components explicitly.
_openElementIndices.Push(_entries.Count); _openElementIndices.Push(_entries.Count);
Append(RenderTreeNode.ChildComponent<TComponent>(sequence)); Append(RenderTreeFrame.ChildComponent<TComponent>(sequence));
} }
private void AssertCanAddAttribute() private void AssertCanAddAttribute()
{ {
if (_lastNonAttributeNodeType != RenderTreeNodeType.Element if (_lastNonAttributeFrameType != RenderTreeFrameType.Element
&& _lastNonAttributeNodeType != RenderTreeNodeType.Component) && _lastNonAttributeFrameType != RenderTreeFrameType.Component)
{ {
throw new InvalidOperationException($"Attributes may only be added immediately after nodes of type {RenderTreeNodeType.Element} or {RenderTreeNodeType.Component}"); throw new InvalidOperationException($"Attributes may only be added immediately after frames of type {RenderTreeFrameType.Element} or {RenderTreeFrameType.Component}");
} }
} }
@ -171,24 +171,24 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
_entries.Clear(); _entries.Clear();
_openElementIndices.Clear(); _openElementIndices.Clear();
_lastNonAttributeNodeType = null; _lastNonAttributeFrameType = null;
} }
/// <summary> /// <summary>
/// Returns the <see cref="RenderTreeNode"/> values that have been appended. /// Returns the <see cref="RenderTreeFrame"/> values that have been appended.
/// </summary> /// </summary>
/// <returns>An array range of <see cref="RenderTreeNode"/> values.</returns> /// <returns>An array range of <see cref="RenderTreeFrame"/> values.</returns>
public ArrayRange<RenderTreeNode> GetNodes() => public ArrayRange<RenderTreeFrame> GetFrames() =>
_entries.ToRange(); _entries.ToRange();
private void Append(in RenderTreeNode node) private void Append(in RenderTreeFrame frame)
{ {
_entries.Append(node); _entries.Append(frame);
var nodeType = node.NodeType; var frameType = frame.FrameType;
if (nodeType != RenderTreeNodeType.Attribute) if (frameType != RenderTreeFrameType.Attribute)
{ {
_lastNonAttributeNodeType = node.NodeType; _lastNonAttributeFrameType = frame.FrameType;
} }
} }
} }

View File

@ -25,12 +25,12 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// Gets the latest render tree. That is, the result of applying the <see cref="Edits"/> /// Gets the latest render tree. That is, the result of applying the <see cref="Edits"/>
/// to the previous state. /// to the previous state.
/// </summary> /// </summary>
public ArrayRange<RenderTreeNode> CurrentState { get; } public ArrayRange<RenderTreeFrame> CurrentState { get; }
internal RenderTreeDiff( internal RenderTreeDiff(
int componentId, int componentId,
ArrayRange<RenderTreeEdit> entries, ArrayRange<RenderTreeEdit> entries,
ArrayRange<RenderTreeNode> referenceTree) ArrayRange<RenderTreeFrame> referenceTree)
{ {
ComponentId = componentId; ComponentId = componentId;
Edits = entries; Edits = entries;

View File

@ -20,15 +20,15 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// <summary> /// <summary>
/// As well as computing the diff between the two trees, this method also has the side-effect /// As well as computing the diff between the two trees, this method also has the side-effect
/// of instantiating child components on newly-inserted Component nodes, and copying the existing /// of instantiating child components on newly-inserted Component frames, and copying the existing
/// component instances onto retained Component nodes. It's particularly convenient to do that /// component instances onto retained Component frames. It's particularly convenient to do that
/// here because we have the right information and are already walking the trees to do the diff. /// here because we have the right information and are already walking the trees to do the diff.
/// </summary> /// </summary>
public void ApplyNewRenderTreeVersion( public void ApplyNewRenderTreeVersion(
RenderBatchBuilder batchBuilder, RenderBatchBuilder batchBuilder,
int componentId, int componentId,
ArrayRange<RenderTreeNode> oldTree, ArrayRange<RenderTreeFrame> oldTree,
ArrayRange<RenderTreeNode> newTree) ArrayRange<RenderTreeFrame> newTree)
{ {
_entries.Clear(); _entries.Clear();
var siblingIndex = 0; var siblingIndex = 0;
@ -42,8 +42,8 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
private void AppendDiffEntriesForRange( private void AppendDiffEntriesForRange(
RenderBatchBuilder batchBuilder, RenderBatchBuilder batchBuilder,
RenderTreeNode[] oldTree, int oldStartIndex, int oldEndIndexExcl, RenderTreeFrame[] oldTree, int oldStartIndex, int oldEndIndexExcl,
RenderTreeNode[] newTree, int newStartIndex, int newEndIndexExcl, RenderTreeFrame[] newTree, int newStartIndex, int newEndIndexExcl,
ref int siblingIndex) ref int siblingIndex)
{ {
var hasMoreOld = oldEndIndexExcl > oldStartIndex; var hasMoreOld = oldEndIndexExcl > oldStartIndex;
@ -57,7 +57,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
if (oldSeq == newSeq) if (oldSeq == newSeq)
{ {
AppendDiffEntriesForNodesWithSameSequence(batchBuilder, oldTree, oldStartIndex, newTree, newStartIndex, ref siblingIndex); AppendDiffEntriesForFramesWithSameSequence(batchBuilder, oldTree, oldStartIndex, newTree, newStartIndex, ref siblingIndex);
oldStartIndex = NextSiblingIndex(oldTree[oldStartIndex], oldStartIndex); oldStartIndex = NextSiblingIndex(oldTree[oldStartIndex], oldStartIndex);
newStartIndex = NextSiblingIndex(newTree[newStartIndex], newStartIndex); newStartIndex = NextSiblingIndex(newTree[newStartIndex], newStartIndex);
hasMoreOld = oldEndIndexExcl > oldStartIndex; hasMoreOld = oldEndIndexExcl > oldStartIndex;
@ -132,22 +132,22 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
if (treatAsInsert) if (treatAsInsert)
{ {
ref var newNode = ref newTree[newStartIndex]; ref var newFrame = ref newTree[newStartIndex];
var newNodeType = newNode.NodeType; var newFrameType = newFrame.FrameType;
if (newNodeType == RenderTreeNodeType.Attribute) if (newFrameType == RenderTreeFrameType.Attribute)
{ {
Append(RenderTreeEdit.SetAttribute(siblingIndex, newStartIndex)); Append(RenderTreeEdit.SetAttribute(siblingIndex, newStartIndex));
newStartIndex++; newStartIndex++;
} }
else else
{ {
if (newNodeType == RenderTreeNodeType.Element || newNodeType == RenderTreeNodeType.Component) if (newFrameType == RenderTreeFrameType.Element || newFrameType == RenderTreeFrameType.Component)
{ {
InstantiateChildComponents(batchBuilder, newTree, newStartIndex); InstantiateChildComponents(batchBuilder, newTree, newStartIndex);
} }
Append(RenderTreeEdit.PrependNode(siblingIndex, newStartIndex)); Append(RenderTreeEdit.PrependFrame(siblingIndex, newStartIndex));
newStartIndex = NextSiblingIndex(newNode, newStartIndex); newStartIndex = NextSiblingIndex(newFrame, newStartIndex);
siblingIndex++; siblingIndex++;
} }
@ -156,22 +156,22 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
} }
else else
{ {
ref var oldNode = ref oldTree[oldStartIndex]; ref var oldFrame = ref oldTree[oldStartIndex];
var oldNodeType = oldNode.NodeType; var oldFrameType = oldFrame.FrameType;
if (oldNodeType == RenderTreeNodeType.Attribute) if (oldFrameType == RenderTreeFrameType.Attribute)
{ {
Append(RenderTreeEdit.RemoveAttribute(siblingIndex, oldNode.AttributeName)); Append(RenderTreeEdit.RemoveAttribute(siblingIndex, oldFrame.AttributeName));
oldStartIndex++; oldStartIndex++;
} }
else else
{ {
if (oldNodeType == RenderTreeNodeType.Element || oldNodeType == RenderTreeNodeType.Component) if (oldFrameType == RenderTreeFrameType.Element || oldFrameType == RenderTreeFrameType.Component)
{ {
DisposeChildComponents(batchBuilder, oldTree, oldStartIndex); DisposeChildComponents(batchBuilder, oldTree, oldStartIndex);
} }
Append(RenderTreeEdit.RemoveNode(siblingIndex)); Append(RenderTreeEdit.RemoveFrame(siblingIndex));
oldStartIndex = NextSiblingIndex(oldNode, oldStartIndex); oldStartIndex = NextSiblingIndex(oldFrame, oldStartIndex);
} }
hasMoreOld = oldEndIndexExcl > oldStartIndex; hasMoreOld = oldEndIndexExcl > oldStartIndex;
prevOldSeq = oldSeq; prevOldSeq = oldSeq;
@ -182,28 +182,28 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
private void UpdateRetainedChildComponent( private void UpdateRetainedChildComponent(
RenderBatchBuilder batchBuilder, RenderBatchBuilder batchBuilder,
RenderTreeNode[] oldTree, int oldComponentIndex, RenderTreeFrame[] oldTree, int oldComponentIndex,
RenderTreeNode[] newTree, int newComponentIndex) RenderTreeFrame[] newTree, int newComponentIndex)
{ {
// The algorithm here is the same as in AppendDiffEntriesForRange, except that // The algorithm here is the same as in AppendDiffEntriesForRange, except that
// here we don't optimise for loops - we assume that both sequences are forward-only. // here we don't optimise for loops - we assume that both sequences are forward-only.
// That's because this is true for all currently supported scenarios, and it means // That's because this is true for all currently supported scenarios, and it means
// fewer steps here. // fewer steps here.
ref var oldComponentNode = ref oldTree[oldComponentIndex]; ref var oldComponentFrame = ref oldTree[oldComponentIndex];
ref var newComponentNode = ref newTree[newComponentIndex]; ref var newComponentFrame = ref newTree[newComponentIndex];
var componentId = oldComponentNode.ComponentId; var componentId = oldComponentFrame.ComponentId;
var componentInstance = oldComponentNode.Component; var componentInstance = oldComponentFrame.Component;
var hasSetAnyProperty = false; var hasSetAnyProperty = false;
// Preserve the actual componentInstance // Preserve the actual componentInstance
newComponentNode.SetChildComponentInstance(componentId, componentInstance); newComponentFrame.SetChildComponentInstance(componentId, componentInstance);
// Now locate any added/changed/removed properties // Now locate any added/changed/removed properties
var oldStartIndex = oldComponentIndex + 1; var oldStartIndex = oldComponentIndex + 1;
var newStartIndex = newComponentIndex + 1; var newStartIndex = newComponentIndex + 1;
var oldEndIndexIncl = oldComponentNode.ElementDescendantsEndIndex; var oldEndIndexIncl = oldComponentFrame.ElementDescendantsEndIndex;
var newEndIndexIncl = newComponentNode.ElementDescendantsEndIndex; var newEndIndexIncl = newComponentFrame.ElementDescendantsEndIndex;
var hasMoreOld = oldEndIndexIncl >= oldStartIndex; var hasMoreOld = oldEndIndexIncl >= oldStartIndex;
var hasMoreNew = newEndIndexIncl >= newStartIndex; var hasMoreNew = newEndIndexIncl >= newStartIndex;
while (hasMoreOld || hasMoreNew) while (hasMoreOld || hasMoreNew)
@ -213,15 +213,15 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
if (oldSeq == newSeq) if (oldSeq == newSeq)
{ {
ref var oldNode = ref oldTree[oldStartIndex]; ref var oldFrame = ref oldTree[oldStartIndex];
ref var newNode = ref newTree[newStartIndex]; ref var newFrame = ref newTree[newStartIndex];
var oldName = oldNode.AttributeName; var oldName = oldFrame.AttributeName;
var newName = newNode.AttributeName; var newName = newFrame.AttributeName;
var newPropertyValue = newNode.AttributeValue; var newPropertyValue = newFrame.AttributeValue;
if (string.Equals(oldName, newName, StringComparison.Ordinal)) if (string.Equals(oldName, newName, StringComparison.Ordinal))
{ {
// Using Equals to account for string comparisons, nulls, etc. // Using Equals to account for string comparisons, nulls, etc.
var oldPropertyValue = oldNode.AttributeValue; var oldPropertyValue = oldFrame.AttributeValue;
if (!Equals(oldPropertyValue, newPropertyValue)) if (!Equals(oldPropertyValue, newPropertyValue))
{ {
SetChildComponentProperty(componentInstance, newName, newPropertyValue); SetChildComponentProperty(componentInstance, newName, newPropertyValue);
@ -252,16 +252,16 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
if (treatAsInsert) if (treatAsInsert)
{ {
ref var newNode = ref newTree[newStartIndex]; ref var newFrame = ref newTree[newStartIndex];
SetChildComponentProperty(componentInstance, newNode.AttributeName, newNode.AttributeValue); SetChildComponentProperty(componentInstance, newFrame.AttributeName, newFrame.AttributeValue);
hasSetAnyProperty = true; hasSetAnyProperty = true;
newStartIndex++; newStartIndex++;
hasMoreNew = newEndIndexIncl >= newStartIndex; hasMoreNew = newEndIndexIncl >= newStartIndex;
} }
else else
{ {
ref var oldNode = ref oldTree[oldStartIndex]; ref var oldFrame = ref oldTree[oldStartIndex];
RemoveChildComponentProperty(componentInstance, oldNode.AttributeName); RemoveChildComponentProperty(componentInstance, oldFrame.AttributeName);
hasSetAnyProperty = true; hasSetAnyProperty = true;
oldStartIndex++; oldStartIndex++;
hasMoreOld = oldEndIndexIncl >= oldStartIndex; hasMoreOld = oldEndIndexIncl >= oldStartIndex;
@ -271,7 +271,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
if (hasSetAnyProperty) if (hasSetAnyProperty)
{ {
TriggerChildComponentRender(batchBuilder, newComponentNode); TriggerChildComponentRender(batchBuilder, newComponentFrame);
} }
} }
@ -312,67 +312,67 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
return property; return property;
} }
private static int NextSiblingIndex(in RenderTreeNode node, int nodeIndex) private static int NextSiblingIndex(in RenderTreeFrame frame, int frameIndex)
{ {
var descendantsEndIndex = node.ElementDescendantsEndIndex; var descendantsEndIndex = frame.ElementDescendantsEndIndex;
return (descendantsEndIndex == 0 ? nodeIndex : descendantsEndIndex) + 1; return (descendantsEndIndex == 0 ? frameIndex : descendantsEndIndex) + 1;
} }
private void AppendDiffEntriesForNodesWithSameSequence( private void AppendDiffEntriesForFramesWithSameSequence(
RenderBatchBuilder batchBuilder, RenderBatchBuilder batchBuilder,
RenderTreeNode[] oldTree, int oldNodeIndex, RenderTreeFrame[] oldTree, int oldFrameIndex,
RenderTreeNode[] newTree, int newNodeIndex, RenderTreeFrame[] newTree, int newFrameIndex,
ref int siblingIndex) ref int siblingIndex)
{ {
ref var oldNode = ref oldTree[oldNodeIndex]; ref var oldFrame = ref oldTree[oldFrameIndex];
ref var newNode = ref newTree[newNodeIndex]; ref var newFrame = ref newTree[newFrameIndex];
// We can assume that the old and new nodes are of the same type, because they correspond // We can assume that the old and new frames are of the same type, because they correspond
// to the same sequence number (and if not, the behaviour is undefined). // to the same sequence number (and if not, the behaviour is undefined).
switch (newTree[newNodeIndex].NodeType) switch (newTree[newFrameIndex].FrameType)
{ {
case RenderTreeNodeType.Text: case RenderTreeFrameType.Text:
{ {
var oldText = oldNode.TextContent; var oldText = oldFrame.TextContent;
var newText = newNode.TextContent; var newText = newFrame.TextContent;
if (!string.Equals(oldText, newText, StringComparison.Ordinal)) if (!string.Equals(oldText, newText, StringComparison.Ordinal))
{ {
Append(RenderTreeEdit.UpdateText(siblingIndex, newNodeIndex)); Append(RenderTreeEdit.UpdateText(siblingIndex, newFrameIndex));
} }
siblingIndex++; siblingIndex++;
break; break;
} }
case RenderTreeNodeType.Element: case RenderTreeFrameType.Element:
{ {
var oldElementName = oldNode.ElementName; var oldElementName = oldFrame.ElementName;
var newElementName = newNode.ElementName; var newElementName = newFrame.ElementName;
if (string.Equals(oldElementName, newElementName, StringComparison.Ordinal)) if (string.Equals(oldElementName, newElementName, StringComparison.Ordinal))
{ {
var oldNodeAttributesEndIndexExcl = GetAttributesEndIndexExclusive(oldTree, oldNodeIndex); var oldFrameAttributesEndIndexExcl = GetAttributesEndIndexExclusive(oldTree, oldFrameIndex);
var newNodeAttributesEndIndexExcl = GetAttributesEndIndexExclusive(newTree, newNodeIndex); var newFrameAttributesEndIndexExcl = GetAttributesEndIndexExclusive(newTree, newFrameIndex);
// Diff the attributes // Diff the attributes
AppendDiffEntriesForRange( AppendDiffEntriesForRange(
batchBuilder, batchBuilder,
oldTree, oldNodeIndex + 1, oldNodeAttributesEndIndexExcl, oldTree, oldFrameIndex + 1, oldFrameAttributesEndIndexExcl,
newTree, newNodeIndex + 1, newNodeAttributesEndIndexExcl, newTree, newFrameIndex + 1, newFrameAttributesEndIndexExcl,
ref siblingIndex); ref siblingIndex);
// Diff the children // Diff the children
var oldNodeChildrenEndIndexExcl = oldNode.ElementDescendantsEndIndex + 1; var oldFrameChildrenEndIndexExcl = oldFrame.ElementDescendantsEndIndex + 1;
var newNodeChildrenEndIndexExcl = newNode.ElementDescendantsEndIndex + 1; var newFrameChildrenEndIndexExcl = newFrame.ElementDescendantsEndIndex + 1;
var hasChildrenToProcess = var hasChildrenToProcess =
oldNodeChildrenEndIndexExcl > oldNodeAttributesEndIndexExcl || oldFrameChildrenEndIndexExcl > oldFrameAttributesEndIndexExcl ||
newNodeChildrenEndIndexExcl > newNodeAttributesEndIndexExcl; newFrameChildrenEndIndexExcl > newFrameAttributesEndIndexExcl;
if (hasChildrenToProcess) if (hasChildrenToProcess)
{ {
Append(RenderTreeEdit.StepIn(siblingIndex)); Append(RenderTreeEdit.StepIn(siblingIndex));
var childSiblingIndex = 0; var childSiblingIndex = 0;
AppendDiffEntriesForRange( AppendDiffEntriesForRange(
batchBuilder, batchBuilder,
oldTree, oldNodeAttributesEndIndexExcl, oldNodeChildrenEndIndexExcl, oldTree, oldFrameAttributesEndIndexExcl, oldFrameChildrenEndIndexExcl,
newTree, newNodeAttributesEndIndexExcl, newNodeChildrenEndIndexExcl, newTree, newFrameAttributesEndIndexExcl, newFrameChildrenEndIndexExcl,
ref childSiblingIndex); ref childSiblingIndex);
Append(RenderTreeEdit.StepOut()); Append(RenderTreeEdit.StepOut());
siblingIndex++; siblingIndex++;
@ -385,51 +385,51 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
else else
{ {
// Elements with different names are treated as completely unrelated // Elements with different names are treated as completely unrelated
InstantiateChildComponents(batchBuilder, newTree, newNodeIndex); InstantiateChildComponents(batchBuilder, newTree, newFrameIndex);
DisposeChildComponents(batchBuilder, oldTree, oldNodeIndex); DisposeChildComponents(batchBuilder, oldTree, oldFrameIndex);
Append(RenderTreeEdit.PrependNode(siblingIndex, newNodeIndex)); Append(RenderTreeEdit.PrependFrame(siblingIndex, newFrameIndex));
siblingIndex++; siblingIndex++;
Append(RenderTreeEdit.RemoveNode(siblingIndex)); Append(RenderTreeEdit.RemoveFrame(siblingIndex));
} }
break; break;
} }
case RenderTreeNodeType.Component: case RenderTreeFrameType.Component:
{ {
var oldComponentType = oldNode.ComponentType; var oldComponentType = oldFrame.ComponentType;
var newComponentType = newNode.ComponentType; var newComponentType = newFrame.ComponentType;
if (oldComponentType == newComponentType) if (oldComponentType == newComponentType)
{ {
UpdateRetainedChildComponent( UpdateRetainedChildComponent(
batchBuilder, batchBuilder,
oldTree, oldNodeIndex, oldTree, oldFrameIndex,
newTree, newNodeIndex); newTree, newFrameIndex);
siblingIndex++; siblingIndex++;
} }
else else
{ {
// Child components of different types are treated as completely unrelated // Child components of different types are treated as completely unrelated
InstantiateChildComponents(batchBuilder, newTree, newNodeIndex); InstantiateChildComponents(batchBuilder, newTree, newFrameIndex);
DisposeChildComponents(batchBuilder, oldTree, oldNodeIndex); DisposeChildComponents(batchBuilder, oldTree, oldFrameIndex);
Append(RenderTreeEdit.PrependNode(siblingIndex, newNodeIndex)); Append(RenderTreeEdit.PrependFrame(siblingIndex, newFrameIndex));
siblingIndex++; siblingIndex++;
Append(RenderTreeEdit.RemoveNode(siblingIndex)); Append(RenderTreeEdit.RemoveFrame(siblingIndex));
} }
break; break;
} }
case RenderTreeNodeType.Attribute: case RenderTreeFrameType.Attribute:
{ {
var oldName = oldNode.AttributeName; var oldName = oldFrame.AttributeName;
var newName = newNode.AttributeName; var newName = newFrame.AttributeName;
if (string.Equals(oldName, newName, StringComparison.Ordinal)) if (string.Equals(oldName, newName, StringComparison.Ordinal))
{ {
// Using Equals to account for string comparisons, nulls, etc. // Using Equals to account for string comparisons, nulls, etc.
var valueChanged = !Equals(oldNode.AttributeValue, newNode.AttributeValue); var valueChanged = !Equals(oldFrame.AttributeValue, newFrame.AttributeValue);
if (valueChanged) if (valueChanged)
{ {
Append(RenderTreeEdit.SetAttribute(siblingIndex, newNodeIndex)); Append(RenderTreeEdit.SetAttribute(siblingIndex, newFrameIndex));
} }
} }
else else
@ -437,24 +437,24 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
// Since this code path is never reachable for Razor components (because you // Since this code path is never reachable for Razor components (because you
// can't have two different attribute names from the same source sequence), we // can't have two different attribute names from the same source sequence), we
// could consider removing the 'name equality' check entirely for perf // could consider removing the 'name equality' check entirely for perf
Append(RenderTreeEdit.SetAttribute(siblingIndex, newNodeIndex)); Append(RenderTreeEdit.SetAttribute(siblingIndex, newFrameIndex));
Append(RenderTreeEdit.RemoveAttribute(siblingIndex, oldName)); Append(RenderTreeEdit.RemoveAttribute(siblingIndex, oldName));
} }
break; break;
} }
default: default:
throw new NotImplementedException($"Encountered unsupported node type during diffing: {newTree[newNodeIndex].NodeType}"); throw new NotImplementedException($"Encountered unsupported frame type during diffing: {newTree[newFrameIndex].FrameType}");
} }
} }
private int GetAttributesEndIndexExclusive(RenderTreeNode[] tree, int rootIndex) private int GetAttributesEndIndexExclusive(RenderTreeFrame[] tree, int rootIndex)
{ {
var descendantsEndIndex = tree[rootIndex].ElementDescendantsEndIndex; var descendantsEndIndex = tree[rootIndex].ElementDescendantsEndIndex;
var index = rootIndex + 1; var index = rootIndex + 1;
for (; index <= descendantsEndIndex; index++) for (; index <= descendantsEndIndex; index++)
{ {
if (tree[index].NodeType != RenderTreeNodeType.Attribute) if (tree[index].FrameType != RenderTreeFrameType.Attribute)
{ {
break; break;
} }
@ -467,7 +467,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
if (entry.Type == RenderTreeEditType.StepOut) if (entry.Type == RenderTreeEditType.StepOut)
{ {
// If the preceding node is a StepIn, then the StepOut cancels it out // If the preceding frame is a StepIn, then the StepOut cancels it out
var previousIndex = _entries.Count - 1; var previousIndex = _entries.Count - 1;
if (previousIndex >= 0 && _entries.Buffer[previousIndex].Type == RenderTreeEditType.StepIn) if (previousIndex >= 0 && _entries.Buffer[previousIndex].Type == RenderTreeEditType.StepIn)
{ {
@ -479,41 +479,41 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
_entries.Append(entry); _entries.Append(entry);
} }
private void InstantiateChildComponents(RenderBatchBuilder batchBuilder, RenderTreeNode[] nodes, int elementOrComponentIndex) private void InstantiateChildComponents(RenderBatchBuilder batchBuilder, RenderTreeFrame[] frames, int elementOrComponentIndex)
{ {
var endIndex = nodes[elementOrComponentIndex].ElementDescendantsEndIndex; var endIndex = frames[elementOrComponentIndex].ElementDescendantsEndIndex;
for (var i = elementOrComponentIndex; i <= endIndex; i++) for (var i = elementOrComponentIndex; i <= endIndex; i++)
{ {
ref var node = ref nodes[i]; ref var frame = ref frames[i];
if (node.NodeType == RenderTreeNodeType.Component) if (frame.FrameType == RenderTreeFrameType.Component)
{ {
if (node.Component != null) if (frame.Component != null)
{ {
throw new InvalidOperationException($"Child component already exists during {nameof(InstantiateChildComponents)}"); throw new InvalidOperationException($"Child component already exists during {nameof(InstantiateChildComponents)}");
} }
_renderer.InstantiateChildComponent(nodes, i); _renderer.InstantiateChildComponent(frames, i);
var childComponentInstance = node.Component; var childComponentInstance = frame.Component;
// All descendants of a component are its properties // All descendants of a component are its properties
var componentDescendantsEndIndex = node.ElementDescendantsEndIndex; var componentDescendantsEndIndex = frame.ElementDescendantsEndIndex;
for (var attributeNodeIndex = i + 1; attributeNodeIndex <= componentDescendantsEndIndex; attributeNodeIndex++) for (var attributeFrameIndex = i + 1; attributeFrameIndex <= componentDescendantsEndIndex; attributeFrameIndex++)
{ {
ref var attributeNode = ref nodes[attributeNodeIndex]; ref var attributeFrame = ref frames[attributeFrameIndex];
SetChildComponentProperty( SetChildComponentProperty(
childComponentInstance, childComponentInstance,
attributeNode.AttributeName, attributeFrame.AttributeName,
attributeNode.AttributeValue); attributeFrame.AttributeValue);
} }
TriggerChildComponentRender(batchBuilder, node); TriggerChildComponentRender(batchBuilder, frame);
} }
} }
} }
private void TriggerChildComponentRender(RenderBatchBuilder batchBuilder, in RenderTreeNode node) private void TriggerChildComponentRender(RenderBatchBuilder batchBuilder, in RenderTreeFrame frame)
{ {
if (node.Component is IHandlePropertiesChanged notifyableComponent) if (frame.Component is IHandlePropertiesChanged notifyableComponent)
{ {
// TODO: Ensure any exceptions thrown here are handled equivalently to // TODO: Ensure any exceptions thrown here are handled equivalently to
// unhandled exceptions during rendering. // unhandled exceptions during rendering.
@ -525,18 +525,18 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
// can control whether any given set of property changes cause re-rendering. // can control whether any given set of property changes cause re-rendering.
// Not doing so yet because it's unclear that the usage patterns would be // Not doing so yet because it's unclear that the usage patterns would be
// good to use. // good to use.
_renderer.RenderInExistingBatch(batchBuilder, node.ComponentId); _renderer.RenderInExistingBatch(batchBuilder, frame.ComponentId);
} }
private void DisposeChildComponents(RenderBatchBuilder batchBuilder, RenderTreeNode[] nodes, int elementOrComponentIndex) private void DisposeChildComponents(RenderBatchBuilder batchBuilder, RenderTreeFrame[] frames, int elementOrComponentIndex)
{ {
var endIndex = nodes[elementOrComponentIndex].ElementDescendantsEndIndex; var endIndex = frames[elementOrComponentIndex].ElementDescendantsEndIndex;
for (var i = elementOrComponentIndex; i <= endIndex; i++) for (var i = elementOrComponentIndex; i <= endIndex; i++)
{ {
ref var node = ref nodes[i]; ref var frame = ref frames[i];
if (node.NodeType == RenderTreeNodeType.Component) if (frame.FrameType == RenderTreeFrameType.Component)
{ {
_renderer.DisposeInExistingBatch(batchBuilder, node.ComponentId); _renderer.DisposeInExistingBatch(batchBuilder, frame.ComponentId);
} }
} }
} }

View File

@ -14,14 +14,14 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
public RenderTreeEditType Type { get; private set; } public RenderTreeEditType Type { get; private set; }
/// <summary> /// <summary>
/// Gets the index of the sibling node that the edit relates to. /// Gets the index of the sibling frame that the edit relates to.
/// </summary> /// </summary>
public int SiblingIndex { get; private set; } public int SiblingIndex { get; private set; }
/// <summary> /// <summary>
/// Gets the index of related data in an associated render tree. For example, if the /// Gets the index of related data in an associated render tree. For example, if the
/// <see cref="Type"/> value is <see cref="RenderTreeEditType.PrependNode"/>, gets the /// <see cref="Type"/> value is <see cref="RenderTreeEditType.PrependFrame"/>, gets the
/// index of the new node data in an associated render tree. /// index of the new frame data in an associated render tree.
/// </summary> /// </summary>
public int NewTreeIndex { get; private set; } public int NewTreeIndex { get; private set; }
@ -31,15 +31,15 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// </summary> /// </summary>
public string RemovedAttributeName { get; private set; } public string RemovedAttributeName { get; private set; }
internal static RenderTreeEdit RemoveNode(int siblingIndex) => new RenderTreeEdit internal static RenderTreeEdit RemoveFrame(int siblingIndex) => new RenderTreeEdit
{ {
Type = RenderTreeEditType.RemoveNode, Type = RenderTreeEditType.RemoveFrame,
SiblingIndex = siblingIndex SiblingIndex = siblingIndex
}; };
internal static RenderTreeEdit PrependNode(int siblingIndex, int newTreeIndex) => new RenderTreeEdit internal static RenderTreeEdit PrependFrame(int siblingIndex, int newTreeIndex) => new RenderTreeEdit
{ {
Type = RenderTreeEditType.PrependNode, Type = RenderTreeEditType.PrependFrame,
SiblingIndex = siblingIndex, SiblingIndex = siblingIndex,
NewTreeIndex = newTreeIndex NewTreeIndex = newTreeIndex
}; };
@ -51,11 +51,11 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
NewTreeIndex = newTreeIndex NewTreeIndex = newTreeIndex
}; };
internal static RenderTreeEdit SetAttribute(int siblingIndex, int newNodeIndex) => new RenderTreeEdit internal static RenderTreeEdit SetAttribute(int siblingIndex, int newFrameIndex) => new RenderTreeEdit
{ {
Type = RenderTreeEditType.SetAttribute, Type = RenderTreeEditType.SetAttribute,
SiblingIndex = siblingIndex, SiblingIndex = siblingIndex,
NewTreeIndex = newNodeIndex NewTreeIndex = newFrameIndex
}; };
internal static RenderTreeEdit RemoveAttribute(int siblingIndex, string name) => new RenderTreeEdit internal static RenderTreeEdit RemoveAttribute(int siblingIndex, string name) => new RenderTreeEdit

View File

@ -9,40 +9,40 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
public enum RenderTreeEditType: int public enum RenderTreeEditType: int
{ {
/// <summary> /// <summary>
/// Indicates that a new node should be inserted before the specified tree node. /// Indicates that a new frame should be inserted before the specified tree frame.
/// </summary> /// </summary>
PrependNode = 1, PrependFrame = 1,
/// <summary> /// <summary>
/// Indicates that the specified tree node should be removed. /// Indicates that the specified tree frame should be removed.
/// </summary> /// </summary>
RemoveNode = 2, RemoveFrame = 2,
/// <summary> /// <summary>
/// Indicates that an attribute value should be applied to the specified node. /// Indicates that an attribute value should be applied to the specified frame.
/// This may be a change to an existing attribute, or the addition of a new attribute. /// This may be a change to an existing attribute, or the addition of a new attribute.
/// </summary> /// </summary>
SetAttribute = 3, SetAttribute = 3,
/// <summary> /// <summary>
/// Indicates that a named attribute should be removed from the specified node. /// Indicates that a named attribute should be removed from the specified frame.
/// </summary> /// </summary>
RemoveAttribute = 4, RemoveAttribute = 4,
/// <summary> /// <summary>
/// Indicates that the text content of the specified node (which must be a text node) /// Indicates that the text content of the specified frame (which must be a text frame)
/// should be updated. /// should be updated.
/// </summary> /// </summary>
UpdateText = 5, UpdateText = 5,
/// <summary> /// <summary>
/// Indicates that the edit position should move inside the specified node. /// Indicates that the edit position should move inside the specified frame.
/// </summary> /// </summary>
StepIn = 6, StepIn = 6,
/// <summary> /// <summary>
/// Indicates that there are no further edit operations on the current node, and the /// Indicates that there are no further edit operations on the current frame, and the
/// edit position should move back to the parent node. /// edit position should move back to the parent frame.
/// </summary> /// </summary>
StepOut = 7, StepOut = 7,
} }

View File

@ -13,111 +13,111 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
/// <summary> /// <summary>
/// Represents an entry in a tree of user interface (UI) items. /// Represents an entry in a tree of user interface (UI) items.
/// </summary> /// </summary>
public struct RenderTreeNode public struct RenderTreeFrame
{ {
/// <summary> /// <summary>
/// Gets the sequence number of the node. Sequence numbers indicate the relative source /// Gets the sequence number of the frame. Sequence numbers indicate the relative source
/// positions of the instructions that inserted the nodes. Sequence numbers are only /// positions of the instructions that inserted the frames. Sequence numbers are only
/// comparable within the same sequence (typically, the same source method). /// comparable within the same sequence (typically, the same source method).
/// </summary> /// </summary>
public int Sequence { get; private set; } public int Sequence { get; private set; }
/// <summary> /// <summary>
/// Describes the type of this node. /// Describes the type of this frame.
/// </summary> /// </summary>
public RenderTreeNodeType NodeType { get; private set; } public RenderTreeFrameType FrameType { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Element"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Element"/>,
/// gets a name representing the type of the element. Otherwise, the value is <see langword="null"/>. /// gets a name representing the type of the element. Otherwise, the value is <see langword="null"/>.
/// </summary> /// </summary>
public string ElementName { get; private set; } public string ElementName { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Element"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Element"/>,
/// gets the index of the final descendant node in the tree. The value is /// gets the index of the final descendant frame in the tree. The value is
/// zero if the node is of a different type, or if it has not yet been closed. /// zero if the frame is of a different type, or if it has not yet been closed.
/// </summary> /// </summary>
public int ElementDescendantsEndIndex { get; private set; } public int ElementDescendantsEndIndex { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Text"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Text"/>,
/// gets the content of the text node. Otherwise, the value is <see langword="null"/>. /// gets the content of the text frame. Otherwise, the value is <see langword="null"/>.
/// </summary> /// </summary>
public string TextContent { get; private set; } public string TextContent { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Attribute"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Attribute"/>,
/// gets the attribute name. Otherwise, the value is <see langword="null"/>. /// gets the attribute name. Otherwise, the value is <see langword="null"/>.
/// </summary> /// </summary>
public string AttributeName { get; private set; } public string AttributeName { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Attribute"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Attribute"/>,
/// gets the attribute value. Otherwise, the value is <see langword="null"/>. /// gets the attribute value. Otherwise, the value is <see langword="null"/>.
/// </summary> /// </summary>
public object AttributeValue { get; private set; } public object AttributeValue { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Component"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Component"/>,
/// gets the type of the child component. /// gets the type of the child component.
/// </summary> /// </summary>
public Type ComponentType { get; private set; } public Type ComponentType { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Component"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Component"/>,
/// gets the child component instance identifier. /// gets the child component instance identifier.
/// </summary> /// </summary>
public int ComponentId { get; private set; } public int ComponentId { get; private set; }
/// <summary> /// <summary>
/// If the <see cref="NodeType"/> property equals <see cref="RenderTreeNodeType.Component"/>, /// If the <see cref="FrameType"/> property equals <see cref="RenderTreeFrameType.Component"/>,
/// gets the child component instance. Otherwise, the value is <see langword="null"/>. /// gets the child component instance. Otherwise, the value is <see langword="null"/>.
/// </summary> /// </summary>
public IComponent Component { get; private set; } public IComponent Component { get; private set; }
internal static RenderTreeNode Element(int sequence, string elementName) => new RenderTreeNode internal static RenderTreeFrame Element(int sequence, string elementName) => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Element, FrameType = RenderTreeFrameType.Element,
ElementName = elementName, ElementName = elementName,
}; };
internal static RenderTreeNode Text(int sequence, string textContent) => new RenderTreeNode internal static RenderTreeFrame Text(int sequence, string textContent) => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Text, FrameType = RenderTreeFrameType.Text,
TextContent = textContent ?? string.Empty, TextContent = textContent ?? string.Empty,
}; };
internal static RenderTreeNode Attribute(int sequence, string name, string value) => new RenderTreeNode internal static RenderTreeFrame Attribute(int sequence, string name, string value) => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Attribute, FrameType = RenderTreeFrameType.Attribute,
AttributeName = name, AttributeName = name,
AttributeValue = value AttributeValue = value
}; };
internal static RenderTreeNode Attribute(int sequence, string name, UIEventHandler value) => new RenderTreeNode internal static RenderTreeFrame Attribute(int sequence, string name, UIEventHandler value) => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Attribute, FrameType = RenderTreeFrameType.Attribute,
AttributeName = name, AttributeName = name,
AttributeValue = value AttributeValue = value
}; };
internal static RenderTreeNode Attribute(int sequence, string name, object value) => new RenderTreeNode internal static RenderTreeFrame Attribute(int sequence, string name, object value) => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Attribute, FrameType = RenderTreeFrameType.Attribute,
AttributeName = name, AttributeName = name,
AttributeValue = value AttributeValue = value
}; };
internal static RenderTreeNode ChildComponent<T>(int sequence) where T: IComponent => new RenderTreeNode internal static RenderTreeFrame ChildComponent<T>(int sequence) where T: IComponent => new RenderTreeFrame
{ {
Sequence = sequence, Sequence = sequence,
NodeType = RenderTreeNodeType.Component, FrameType = RenderTreeFrameType.Component,
ComponentType = typeof(T) ComponentType = typeof(T)
}; };
@ -134,8 +134,8 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
internal void SetSequence(int sequence) internal void SetSequence(int sequence)
{ {
// This is only used when appending attribute nodes, because helpers such as @onclick // This is only used when appending attribute frames, because helpers such as @onclick
// need to construct the attribute node in a context where they don't know the sequence // need to construct the attribute frame in a context where they don't know the sequence
// number, so we assign it later // number, so we assign it later
Sequence = sequence; Sequence = sequence;
} }

View File

@ -4,12 +4,12 @@
namespace Microsoft.AspNetCore.Blazor.RenderTree namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
/// <summary> /// <summary>
/// Describes the type of a <see cref="RenderTreeNode"/>. /// Describes the type of a <see cref="RenderTreeFrame"/>.
/// </summary> /// </summary>
public enum RenderTreeNodeType: int public enum RenderTreeFrameType: int
{ {
/// <summary> /// <summary>
/// Represents a container for other nodes. /// Represents a container for other frames.
/// </summary> /// </summary>
Element = 1, Element = 1,
@ -19,7 +19,7 @@ namespace Microsoft.AspNetCore.Blazor.RenderTree
Text = 2, Text = 2,
/// <summary> /// <summary>
/// Represents a key-value pair associated with another <see cref="RenderTreeNode"/>. /// Represents a key-value pair associated with another <see cref="RenderTreeFrame"/>.
/// </summary> /// </summary>
Attribute = 3, Attribute = 3,

View File

@ -4,7 +4,7 @@
namespace Microsoft.AspNetCore.Blazor.RenderTree namespace Microsoft.AspNetCore.Blazor.RenderTree
{ {
/// <summary> /// <summary>
/// Handles an event raised for a <see cref="RenderTreeNode"/>. /// Handles an event raised for a <see cref="RenderTreeFrame"/>.
/// </summary> /// </summary>
public delegate void UIEventHandler(UIEventArgs eventArgs); public delegate void UIEventHandler(UIEventArgs eventArgs);
} }

View File

@ -51,14 +51,14 @@ namespace Microsoft.AspNetCore.Blazor.Rendering
_diffComputer.ApplyNewRenderTreeVersion( _diffComputer.ApplyNewRenderTreeVersion(
batchBuilder, batchBuilder,
_componentId, _componentId,
_renderTreeBuilderPrevious.GetNodes(), _renderTreeBuilderPrevious.GetFrames(),
_renderTreeBuilderCurrent.GetNodes()); _renderTreeBuilderCurrent.GetFrames());
} }
/// <summary> /// <summary>
/// Invokes the handler corresponding to an event. /// Invokes the handler corresponding to an event.
/// </summary> /// </summary>
/// <param name="renderTreeIndex">The index of the current render tree node that holds the event handler to be invoked.</param> /// <param name="renderTreeIndex">The index of the current render tree frame that holds the event handler to be invoked.</param>
/// <param name="eventArgs">Arguments to be passed to the event handler.</param> /// <param name="eventArgs">Arguments to be passed to the event handler.</param>
public void DispatchEvent(int renderTreeIndex, UIEventArgs eventArgs) public void DispatchEvent(int renderTreeIndex, UIEventArgs eventArgs)
{ {
@ -67,11 +67,11 @@ namespace Microsoft.AspNetCore.Blazor.Rendering
throw new ArgumentNullException(nameof(eventArgs)); throw new ArgumentNullException(nameof(eventArgs));
} }
var nodes = _renderTreeBuilderCurrent.GetNodes(); var frames = _renderTreeBuilderCurrent.GetFrames();
var eventHandler = nodes.Array[renderTreeIndex].AttributeValue as UIEventHandler; var eventHandler = frames.Array[renderTreeIndex].AttributeValue as UIEventHandler;
if (eventHandler == null) if (eventHandler == null)
{ {
throw new ArgumentException($"The render tree node at index {renderTreeIndex} does not specify a {nameof(UIEventHandler)}."); throw new ArgumentException($"The render tree frame at index {renderTreeIndex} does not specify a {nameof(UIEventHandler)}.");
} }
eventHandler.Invoke(eventArgs); eventHandler.Invoke(eventArgs);

View File

@ -111,22 +111,22 @@ namespace Microsoft.AspNetCore.Blazor.Rendering
protected void DispatchEvent(int componentId, int renderTreeIndex, UIEventArgs eventArgs) protected void DispatchEvent(int componentId, int renderTreeIndex, UIEventArgs eventArgs)
=> GetRequiredComponentState(componentId).DispatchEvent(renderTreeIndex, eventArgs); => GetRequiredComponentState(componentId).DispatchEvent(renderTreeIndex, eventArgs);
internal void InstantiateChildComponent(RenderTreeNode[] nodes, int componentNodeIndex) internal void InstantiateChildComponent(RenderTreeFrame[] frames, int componentFrameIndex)
{ {
ref var node = ref nodes[componentNodeIndex]; ref var frame = ref frames[componentFrameIndex];
if (node.NodeType != RenderTreeNodeType.Component) if (frame.FrameType != RenderTreeFrameType.Component)
{ {
throw new ArgumentException($"The node's {nameof(RenderTreeNode.NodeType)} property must equal {RenderTreeNodeType.Component}", nameof(node)); throw new ArgumentException($"The frame's {nameof(RenderTreeFrame.FrameType)} property must equal {RenderTreeFrameType.Component}", nameof(frame));
} }
if (node.Component != null) if (frame.Component != null)
{ {
throw new ArgumentException($"The node already has a non-null component instance", nameof(node)); throw new ArgumentException($"The frame already has a non-null component instance", nameof(frame));
} }
var newComponent = (IComponent)Activator.CreateInstance(node.ComponentType); var newComponent = (IComponent)Activator.CreateInstance(frame.ComponentType);
var newComponentId = AssignComponentId(newComponent); var newComponentId = AssignComponentId(newComponent);
node.SetChildComponentInstance(newComponentId, newComponent); frame.SetChildComponentInstance(newComponentId, newComponent);
} }
private ComponentState GetRequiredComponentState(int componentId) private ComponentState GetRequiredComponentState(int componentId)

View File

@ -18,7 +18,7 @@
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Build\Microsoft.AspNetCore.Blazor.Build.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor.Build\Microsoft.AspNetCore.Blazor.Build.csproj" />
<!-- Shared sources --> <!-- Shared sources -->
<Compile Include="..\shared\AssertNode.cs" /> <Compile Include="..\shared\AssertFrame.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -96,8 +96,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
component.BuildRenderTree(treeBuilder); component.BuildRenderTree(treeBuilder);
// Assert // Assert
Assert.Collection(treeBuilder.GetNodes(), Assert.Collection(treeBuilder.GetFrames(),
node => AssertNode.Text(node, "Some plain text", 0)); frame => AssertFrame.Text(frame, "Some plain text", 0));
} }
[Fact] [Fact]
@ -112,17 +112,17 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
"); ");
// Assert // Assert
var nodes = GetRenderTree(component); var frames = GetRenderTree(component);
Assert.Collection(nodes, Assert.Collection(frames,
node => AssertNode.Whitespace(node, 0), frame => AssertFrame.Whitespace(frame, 0),
node => AssertNode.Text(node, "Hello", 1), frame => AssertFrame.Text(frame, "Hello", 1),
node => AssertNode.Whitespace(node, 2), frame => AssertFrame.Whitespace(frame, 2),
node => AssertNode.Whitespace(node, 3), // @((object)null) frame => AssertFrame.Whitespace(frame, 3), // @((object)null)
node => AssertNode.Whitespace(node, 4), frame => AssertFrame.Whitespace(frame, 4),
node => AssertNode.Text(node, "123", 5), frame => AssertFrame.Text(frame, "123", 5),
node => AssertNode.Whitespace(node, 6), frame => AssertFrame.Whitespace(frame, 6),
node => AssertNode.Text(node, new object().ToString(), 7), frame => AssertFrame.Text(frame, new object().ToString(), 7),
node => AssertNode.Whitespace(node, 8)); frame => AssertFrame.Whitespace(frame, 8));
} }
[Fact] [Fact]
@ -139,14 +139,14 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
"); ");
// Assert // Assert
var nodes = GetRenderTree(component); var frames = GetRenderTree(component);
Assert.Collection(nodes, Assert.Collection(frames,
node => AssertNode.Whitespace(node, 0), frame => AssertFrame.Whitespace(frame, 0),
node => AssertNode.Text(node, "First", 1), frame => AssertFrame.Text(frame, "First", 1),
node => AssertNode.Text(node, "Second", 1), frame => AssertFrame.Text(frame, "Second", 1),
node => AssertNode.Text(node, "Third", 1), frame => AssertFrame.Text(frame, "Third", 1),
node => AssertNode.Whitespace(node, 2), frame => AssertFrame.Whitespace(frame, 2),
node => AssertNode.Whitespace(node, 3)); frame => AssertFrame.Whitespace(frame, 3));
} }
[Fact] [Fact]
@ -157,8 +157,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "myelem", 1, 0), frame => AssertFrame.Element(frame, "myelem", 1, 0),
node => AssertNode.Text(node, "Hello", 1)); frame => AssertFrame.Text(frame, "Hello", 1));
} }
[Fact] [Fact]
@ -169,8 +169,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Text(node, "Some text so elem isn't at position 0 ", 0), frame => AssertFrame.Text(frame, "Some text so elem isn't at position 0 ", 0),
node => AssertNode.Element(node, "myelem", 1, 1)); frame => AssertFrame.Element(frame, "myelem", 1, 1));
} }
[Fact] [Fact]
@ -181,8 +181,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Text(node, "Some text so elem isn't at position 0 ", 0), frame => AssertFrame.Text(frame, "Some text so elem isn't at position 0 ", 0),
node => AssertNode.Element(node, "img", 1, 1)); frame => AssertFrame.Element(frame, "img", 1, 1));
} }
[Fact] [Fact]
@ -193,9 +193,9 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 2, 0), frame => AssertFrame.Element(frame, "elem", 2, 0),
node => AssertNode.Attribute(node, "attrib-one", "Value 1", 1), frame => AssertFrame.Attribute(frame, "attrib-one", "Value 1", 1),
node => AssertNode.Attribute(node, "a2", "v2", 2)); frame => AssertFrame.Attribute(frame, "a2", "v2", 2));
} }
[Fact] [Fact]
@ -208,8 +208,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => AssertNode.Attribute(node, "attr", "My string", 1)); frame => AssertFrame.Attribute(frame, "attr", "My string", 1));
} }
[Fact] [Fact]
@ -222,8 +222,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => AssertNode.Attribute(node, "attr", "123", 1)); frame => AssertFrame.Attribute(frame, "attr", "123", 1));
} }
[Fact] [Fact]
@ -236,8 +236,8 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => AssertNode.Attribute(node, "attr", "Hello, WORLD with number 246!", 1)); frame => AssertFrame.Attribute(frame, "attr", "Hello, WORLD with number 246!", 1));
} }
[Fact] [Fact]
@ -259,17 +259,17 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.False((bool)handlerWasCalledProperty.GetValue(component)); Assert.False((bool)handlerWasCalledProperty.GetValue(component));
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => frame =>
{ {
Assert.Equal(RenderTreeNodeType.Attribute, node.NodeType); Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType);
Assert.Equal(1, node.Sequence); Assert.Equal(1, frame.Sequence);
Assert.NotNull(node.AttributeValue); Assert.NotNull(frame.AttributeValue);
((UIEventHandler)node.AttributeValue)(null); ((UIEventHandler)frame.AttributeValue)(null);
Assert.True((bool)handlerWasCalledProperty.GetValue(component)); Assert.True((bool)handlerWasCalledProperty.GetValue(component));
}, },
node => AssertNode.Whitespace(node, 2)); frame => AssertFrame.Whitespace(frame, 2));
} }
[Fact] [Fact]
@ -282,22 +282,22 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
public bool DidInvokeCode { get; set; } = false; public bool DidInvokeCode { get; set; } = false;
}"); }");
var didInvokeCodeProperty = component.GetType().GetProperty("DidInvokeCode"); var didInvokeCodeProperty = component.GetType().GetProperty("DidInvokeCode");
var nodes = GetRenderTree(component); var frames = GetRenderTree(component);
// Assert // Assert
Assert.False((bool)didInvokeCodeProperty.GetValue(component)); Assert.False((bool)didInvokeCodeProperty.GetValue(component));
Assert.Collection(nodes, Assert.Collection(frames,
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => frame =>
{ {
Assert.Equal(RenderTreeNodeType.Attribute, node.NodeType); Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType);
Assert.NotNull(node.AttributeValue); Assert.NotNull(frame.AttributeValue);
Assert.Equal(1, node.Sequence); Assert.Equal(1, frame.Sequence);
((UIEventHandler)node.AttributeValue)(null); ((UIEventHandler)frame.AttributeValue)(null);
Assert.True((bool)didInvokeCodeProperty.GetValue(component)); Assert.True((bool)didInvokeCodeProperty.GetValue(component));
}, },
node => AssertNode.Whitespace(node, 2)); frame => AssertFrame.Whitespace(frame, 2));
} }
[Fact] [Fact]
@ -313,13 +313,13 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
component.BuildRenderTree(treeBuilder); component.BuildRenderTree(treeBuilder);
// Assert // Assert
Assert.Collection(treeBuilder.GetNodes(), Assert.Collection(treeBuilder.GetFrames(),
node => AssertNode.Whitespace(node, 0), frame => AssertFrame.Whitespace(frame, 0),
node => AssertNode.Text(node, typeof(List<string>).FullName, 1)); frame => AssertFrame.Text(frame, typeof(List<string>).FullName, 1));
} }
[Fact] [Fact]
public void SupportsAttributeNodesEvaluatedInline() public void SupportsAttributeFramesEvaluatedInline()
{ {
// Arrange/Act // Arrange/Act
var component = CompileToComponent( var component = CompileToComponent(
@ -336,17 +336,17 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
// Assert // Assert
Assert.False((bool)didInvokeCodeProperty.GetValue(component)); Assert.False((bool)didInvokeCodeProperty.GetValue(component));
Assert.Collection(GetRenderTree(component), Assert.Collection(GetRenderTree(component),
node => AssertNode.Element(node, "elem", 1, 0), frame => AssertFrame.Element(frame, "elem", 1, 0),
node => frame =>
{ {
Assert.Equal(RenderTreeNodeType.Attribute, node.NodeType); Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType);
Assert.NotNull(node.AttributeValue); Assert.NotNull(frame.AttributeValue);
Assert.Equal(1, node.Sequence); Assert.Equal(1, frame.Sequence);
((UIEventHandler)node.AttributeValue)(null); ((UIEventHandler)frame.AttributeValue)(null);
Assert.True((bool)didInvokeCodeProperty.GetValue(component)); Assert.True((bool)didInvokeCodeProperty.GetValue(component));
}, },
node => AssertNode.Whitespace(node, 2)); frame => AssertFrame.Whitespace(frame, 2));
} }
[Fact] [Fact]
@ -361,15 +361,15 @@ namespace Microsoft.AspNetCore.Blazor.Build.Test
component.BuildRenderTree(treeBuilder); component.BuildRenderTree(treeBuilder);
// Assert // Assert
Assert.Collection(treeBuilder.GetNodes(), Assert.Collection(treeBuilder.GetFrames(),
node => AssertNode.Component<TestComponent>(node, 0)); frame => AssertFrame.Component<TestComponent>(frame, 0));
} }
private static ArrayRange<RenderTreeNode> GetRenderTree(IComponent component) private static ArrayRange<RenderTreeFrame> GetRenderTree(IComponent component)
{ {
var treeBuilder = new RenderTreeBuilder(new TestRenderer()); var treeBuilder = new RenderTreeBuilder(new TestRenderer());
component.BuildRenderTree(treeBuilder); component.BuildRenderTree(treeBuilder);
return treeBuilder.GetNodes(); return treeBuilder.GetFrames();
} }
private static IComponent CompileToComponent(string cshtmlSource) private static IComponent CompileToComponent(string cshtmlSource)

View File

@ -17,7 +17,7 @@
<ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" /> <ProjectReference Include="..\..\src\Microsoft.AspNetCore.Blazor\Microsoft.AspNetCore.Blazor.csproj" />
<!-- Shared sources --> <!-- Shared sources -->
<Compile Include="..\shared\AssertNode.cs" /> <Compile Include="..\shared\AssertFrame.cs" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -29,9 +29,9 @@ namespace Microsoft.AspNetCore.Blazor.Test
var builder = new RenderTreeBuilder(new TestRenderer()); var builder = new RenderTreeBuilder(new TestRenderer());
// Assert // Assert
var nodes = builder.GetNodes(); var frames = builder.GetFrames();
Assert.NotNull(nodes.Array); Assert.NotNull(frames.Array);
Assert.Empty(nodes); Assert.Empty(frames);
} }
[Fact] [Fact]
@ -47,11 +47,11 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.AddText(0, "Second item"); builder.AddText(0, "Second item");
// Assert // Assert
var nodes = builder.GetNodes(); var frames = builder.GetFrames();
Assert.Collection(nodes, Assert.Collection(frames,
node => AssertNode.Text(node, "First item"), frame => AssertFrame.Text(frame, "First item"),
node => AssertNode.Text(node, string.Empty), frame => AssertFrame.Text(frame, string.Empty),
node => AssertNode.Text(node, "Second item")); frame => AssertFrame.Text(frame, "Second item"));
} }
[Fact] [Fact]
@ -66,10 +66,10 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.AddText(0, nullObject); builder.AddText(0, nullObject);
// Assert // Assert
var nodes = builder.GetNodes(); var frames = builder.GetFrames();
Assert.Collection(nodes, Assert.Collection(frames,
node => AssertNode.Text(node, "1234"), frame => AssertFrame.Text(frame, "1234"),
node => AssertNode.Text(node, string.Empty)); frame => AssertFrame.Text(frame, string.Empty));
} }
[Fact] [Fact]
@ -82,8 +82,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.OpenElement(0, "my element"); builder.OpenElement(0, "my element");
// Assert // Assert
var node = builder.GetNodes().Single(); var frame = builder.GetFrames().Single();
AssertNode.Element(node, "my element", 0); AssertFrame.Element(frame, "my element", 0);
} }
[Fact] [Fact]
@ -93,14 +93,14 @@ namespace Microsoft.AspNetCore.Blazor.Test
var builder = new RenderTreeBuilder(new TestRenderer()); var builder = new RenderTreeBuilder(new TestRenderer());
// Act // Act
builder.AddText(0, "some node so that the element isn't at position zero"); builder.AddText(0, "some frame so that the element isn't at position zero");
builder.OpenElement(0, "my element"); builder.OpenElement(0, "my element");
builder.CloseElement(); builder.CloseElement();
// Assert // Assert
var nodes = builder.GetNodes(); var frames = builder.GetFrames();
Assert.Equal(2, nodes.Count); Assert.Equal(2, frames.Count);
AssertNode.Element(nodes.Array[1], "my element", 1); AssertFrame.Element(frames.Array[1], "my element", 1);
} }
[Fact] [Fact]
@ -117,9 +117,9 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.AddText(0, "unrelated item"); builder.AddText(0, "unrelated item");
// Assert // Assert
var nodes = builder.GetNodes(); var frames = builder.GetFrames();
Assert.Equal(4, nodes.Count); Assert.Equal(4, frames.Count);
AssertNode.Element(nodes.Array[0], "my element", 2); AssertFrame.Element(frames.Array[0], "my element", 2);
} }
[Fact] [Fact]
@ -147,19 +147,19 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.AddText(0, "standalone text 2"); // 11: standalone text 2 builder.AddText(0, "standalone text 2"); // 11: standalone text 2
// Assert // Assert
Assert.Collection(builder.GetNodes(), Assert.Collection(builder.GetFrames(),
node => AssertNode.Text(node, "standalone text 1"), frame => AssertFrame.Text(frame, "standalone text 1"),
node => AssertNode.Element(node, "root", 10), frame => AssertFrame.Element(frame, "root", 10),
node => AssertNode.Text(node, "root text 1"), frame => AssertFrame.Text(frame, "root text 1"),
node => AssertNode.Text(node, "root text 2"), frame => AssertFrame.Text(frame, "root text 2"),
node => AssertNode.Element(node, "child", 8), frame => AssertFrame.Element(frame, "child", 8),
node => AssertNode.Text(node, "child text"), frame => AssertFrame.Text(frame, "child text"),
node => AssertNode.Element(node, "grandchild", 8), frame => AssertFrame.Element(frame, "grandchild", 8),
node => AssertNode.Text(node, "grandchild text 1"), frame => AssertFrame.Text(frame, "grandchild text 1"),
node => AssertNode.Text(node, "grandchild text 2"), frame => AssertFrame.Text(frame, "grandchild text 2"),
node => AssertNode.Text(node, "root text 3"), frame => AssertFrame.Text(frame, "root text 3"),
node => AssertNode.Element(node, "child 2", 10), frame => AssertFrame.Element(frame, "child 2", 10),
node => AssertNode.Text(node, "standalone text 2")); frame => AssertFrame.Text(frame, "standalone text 2"));
} }
[Fact] [Fact]
@ -180,13 +180,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.CloseElement(); // </myelement> builder.CloseElement(); // </myelement>
// Assert // Assert
Assert.Collection(builder.GetNodes(), Assert.Collection(builder.GetFrames(),
node => AssertNode.Element(node, "myelement", 5), frame => AssertFrame.Element(frame, "myelement", 5),
node => AssertNode.Attribute(node, "attribute1", "value 1"), frame => AssertFrame.Attribute(frame, "attribute1", "value 1"),
node => AssertNode.Attribute(node, "attribute2", "123"), frame => AssertFrame.Attribute(frame, "attribute2", "123"),
node => AssertNode.Element(node, "child", 5), frame => AssertFrame.Element(frame, "child", 5),
node => AssertNode.Attribute(node, "childevent", eventHandler), frame => AssertFrame.Attribute(frame, "childevent", eventHandler),
node => AssertNode.Text(node, "some text")); frame => AssertFrame.Text(frame, "some text"));
} }
[Fact] [Fact]
@ -263,13 +263,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.CloseElement(); // </parent> builder.CloseElement(); // </parent>
// Assert // Assert
Assert.Collection(builder.GetNodes(), Assert.Collection(builder.GetFrames(),
node => AssertNode.Element(node, "parent", 5), frame => AssertFrame.Element(frame, "parent", 5),
node => AssertNode.Component<TestComponent>(node), frame => AssertFrame.Component<TestComponent>(frame),
node => AssertNode.Attribute(node, "child1attribute1", "A"), frame => AssertFrame.Attribute(frame, "child1attribute1", "A"),
node => AssertNode.Attribute(node, "child1attribute2", "B"), frame => AssertFrame.Attribute(frame, "child1attribute2", "B"),
node => AssertNode.Component<TestComponent>(node), frame => AssertFrame.Component<TestComponent>(frame),
node => AssertNode.Attribute(node, "child2attribute", "C")); frame => AssertFrame.Attribute(frame, "child2attribute", "C"));
} }
[Fact] [Fact]
@ -286,7 +286,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
builder.Clear(); builder.Clear();
// Assert // Assert
Assert.Empty(builder.GetNodes()); Assert.Empty(builder.GetFrames());
} }
private class TestComponent : IComponent private class TestComponent : IComponent

View File

@ -28,8 +28,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
} }
[Theory] [Theory]
[MemberData(nameof(RecognizesEquivalentNodesAsSameCases))] [MemberData(nameof(RecognizesEquivalentFramesAsSameCases))]
public void RecognizesEquivalentNodesAsSame(Action<RenderTreeBuilder> appendAction) public void RecognizesEquivalentFramesAsSame(Action<RenderTreeBuilder> appendAction)
{ {
// Arrange // Arrange
appendAction(oldTree); appendAction(oldTree);
@ -42,7 +42,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Empty(result.Edits); Assert.Empty(result.Edits);
} }
public static IEnumerable<object[]> RecognizesEquivalentNodesAsSameCases() public static IEnumerable<object[]> RecognizesEquivalentFramesAsSameCases()
=> new Action<RenderTreeBuilder>[] => new Action<RenderTreeBuilder>[]
{ {
builder => builder.AddText(0, "Hello"), builder => builder.AddText(0, "Hello"),
@ -73,7 +73,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 1); AssertEdit(entry, RenderTreeEditType.PrependFrame, 1);
Assert.Equal(1, entry.NewTreeIndex); Assert.Equal(1, entry.NewTreeIndex);
}); });
} }
@ -93,7 +93,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1));
} }
[Fact] [Fact]
@ -112,8 +112,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1), entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1),
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1));
} }
[Fact] [Fact]
@ -134,12 +134,12 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 1); AssertEdit(entry, RenderTreeEditType.PrependFrame, 1);
Assert.Equal(1, entry.NewTreeIndex); Assert.Equal(1, entry.NewTreeIndex);
}, },
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 2); AssertEdit(entry, RenderTreeEditType.PrependFrame, 2);
Assert.Equal(2, entry.NewTreeIndex); Assert.Equal(2, entry.NewTreeIndex);
}); });
} }
@ -160,8 +160,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 2), entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 2),
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 2)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 2));
} }
[Fact] [Fact]
@ -182,12 +182,12 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 2); AssertEdit(entry, RenderTreeEditType.PrependFrame, 2);
Assert.Equal(2, entry.NewTreeIndex); Assert.Equal(2, entry.NewTreeIndex);
}, },
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 3); AssertEdit(entry, RenderTreeEditType.PrependFrame, 3);
Assert.Equal(3, entry.NewTreeIndex); Assert.Equal(3, entry.NewTreeIndex);
}); });
} }
@ -210,12 +210,12 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 1); AssertEdit(entry, RenderTreeEditType.PrependFrame, 1);
Assert.Equal(1, entry.NewTreeIndex); Assert.Equal(1, entry.NewTreeIndex);
}, },
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 2); AssertEdit(entry, RenderTreeEditType.PrependFrame, 2);
Assert.Equal(2, entry.NewTreeIndex); Assert.Equal(2, entry.NewTreeIndex);
}); });
} }
@ -236,8 +236,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1), entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1),
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1));
} }
[Fact] [Fact]
@ -252,8 +252,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 0), entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 0),
entry => AssertEdit(entry, RenderTreeEditType.PrependNode, 0)); entry => AssertEdit(entry, RenderTreeEditType.PrependFrame, 0));
} }
[Fact] [Fact]
@ -302,10 +302,10 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(result.Edits, Assert.Collection(result.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 0); AssertEdit(entry, RenderTreeEditType.PrependFrame, 0);
Assert.Equal(0, entry.NewTreeIndex); Assert.Equal(0, entry.NewTreeIndex);
}, },
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1));
} }
[Fact] [Fact]
@ -330,18 +330,18 @@ namespace Microsoft.AspNetCore.Blazor.Test
Assert.Collection(updatedComponent1.Edits, Assert.Collection(updatedComponent1.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 0); AssertEdit(entry, RenderTreeEditType.PrependFrame, 0);
Assert.Equal(0, entry.NewTreeIndex); Assert.Equal(0, entry.NewTreeIndex);
Assert.IsType<FakeComponent2>(updatedComponent1.CurrentState.Array[0].Component); Assert.IsType<FakeComponent2>(updatedComponent1.CurrentState.Array[0].Component);
}, },
entry => AssertEdit(entry, RenderTreeEditType.RemoveNode, 1)); entry => AssertEdit(entry, RenderTreeEditType.RemoveFrame, 1));
// Assert: Second updated component is the new FakeComponent2 // Assert: Second updated component is the new FakeComponent2
var updatedComponent2 = renderBatch.UpdatedComponents.Array[1]; var updatedComponent2 = renderBatch.UpdatedComponents.Array[1];
Assert.Collection(updatedComponent2.Edits, Assert.Collection(updatedComponent2.Edits,
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 0); AssertEdit(entry, RenderTreeEditType.PrependFrame, 0);
Assert.Equal(0, entry.NewTreeIndex); Assert.Equal(0, entry.NewTreeIndex);
}); });
} }
@ -577,7 +577,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
} }
[Fact] [Fact]
public void InstantiatesChildComponentsForInsertedNodes() public void InstantiatesChildComponentsForInsertedFrames()
{ {
// Arrange // Arrange
oldTree.AddText(10, "text1"); // 0: text1 oldTree.AddText(10, "text1"); // 0: text1
@ -603,37 +603,37 @@ namespace Microsoft.AspNetCore.Blazor.Test
entry => AssertEdit(entry, RenderTreeEditType.StepIn, 1), entry => AssertEdit(entry, RenderTreeEditType.StepIn, 1),
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 0); AssertEdit(entry, RenderTreeEditType.PrependFrame, 0);
Assert.Equal(2, entry.NewTreeIndex); Assert.Equal(2, entry.NewTreeIndex);
var newTreeNode = newTree.GetNodes().Array[entry.NewTreeIndex]; var newTreeFrame = newTree.GetFrames().Array[entry.NewTreeIndex];
Assert.Equal(0, newTreeNode.ComponentId); Assert.Equal(0, newTreeFrame.ComponentId);
Assert.IsType<FakeComponent>(newTreeNode.Component); Assert.IsType<FakeComponent>(newTreeFrame.Component);
}, },
entry => entry =>
{ {
AssertEdit(entry, RenderTreeEditType.PrependNode, 1); AssertEdit(entry, RenderTreeEditType.PrependFrame, 1);
Assert.Equal(3, entry.NewTreeIndex); Assert.Equal(3, entry.NewTreeIndex);
var newTreeNode = newTree.GetNodes().Array[entry.NewTreeIndex]; var newTreeFrame = newTree.GetFrames().Array[entry.NewTreeIndex];
Assert.Equal(1, newTreeNode.ComponentId); Assert.Equal(1, newTreeFrame.ComponentId);
Assert.IsType<FakeComponent2>(newTreeNode.Component); Assert.IsType<FakeComponent2>(newTreeFrame.Component);
}, },
entry => AssertEdit(entry, RenderTreeEditType.StepOut, 0)); entry => AssertEdit(entry, RenderTreeEditType.StepOut, 0));
// Second in batch is the first child component // Second in batch is the first child component
var secondComponentDiff = renderBatch.UpdatedComponents.Array[1]; var secondComponentDiff = renderBatch.UpdatedComponents.Array[1];
Assert.Equal(0, secondComponentDiff.ComponentId); Assert.Equal(0, secondComponentDiff.ComponentId);
Assert.Empty(secondComponentDiff.Edits); // Because FakeComponent produces no nodes Assert.Empty(secondComponentDiff.Edits); // Because FakeComponent produces no frames
Assert.Empty(secondComponentDiff.CurrentState); // Because FakeComponent produces no nodes Assert.Empty(secondComponentDiff.CurrentState); // Because FakeComponent produces no frames
// Third in batch is the second child component // Third in batch is the second child component
var thirdComponentDiff = renderBatch.UpdatedComponents.Array[2]; var thirdComponentDiff = renderBatch.UpdatedComponents.Array[2];
Assert.Equal(1, thirdComponentDiff.ComponentId); Assert.Equal(1, thirdComponentDiff.ComponentId);
Assert.Collection(thirdComponentDiff.Edits, Assert.Collection(thirdComponentDiff.Edits,
entry => AssertEdit(entry, RenderTreeEditType.PrependNode, 0)); entry => AssertEdit(entry, RenderTreeEditType.PrependFrame, 0));
Assert.Collection(thirdComponentDiff.CurrentState, Assert.Collection(thirdComponentDiff.CurrentState,
node => AssertNode.Text(node, $"Hello from {nameof(FakeComponent2)}")); frame => AssertFrame.Text(frame, $"Hello from {nameof(FakeComponent2)}"));
} }
[Fact] [Fact]
@ -649,13 +649,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act // Act
var renderBatch = GetRenderedBatch(); var renderBatch = GetRenderedBatch();
var componentInstance = newTree.GetNodes().First().Component as FakeComponent; var componentInstance = newTree.GetFrames().First().Component as FakeComponent;
// Assert // Assert
Assert.Equal(2, renderBatch.UpdatedComponents.Count); Assert.Equal(2, renderBatch.UpdatedComponents.Count);
var rootComponentDiff = renderBatch.UpdatedComponents.Array[0]; var rootComponentDiff = renderBatch.UpdatedComponents.Array[0];
AssertEdit(rootComponentDiff.Edits.Single(), RenderTreeEditType.PrependNode, 0); AssertEdit(rootComponentDiff.Edits.Single(), RenderTreeEditType.PrependFrame, 0);
Assert.NotNull(componentInstance); Assert.NotNull(componentInstance);
Assert.Equal(123, componentInstance.IntProperty); Assert.Equal(123, componentInstance.IntProperty);
Assert.Equal("some string", componentInstance.StringProperty); Assert.Equal("some string", componentInstance.StringProperty);
@ -674,7 +674,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert // Act/Assert
var ex = Assert.Throws<InvalidOperationException>(() => var ex = Assert.Throws<InvalidOperationException>(() =>
{ {
diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, oldTree.GetNodes(), newTree.GetNodes()); diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, oldTree.GetFrames(), newTree.GetFrames());
}); });
Assert.Equal($"Component of type '{typeof(FakeComponent).FullName}' does not have a property matching the name 'SomeUnknownProperty'.", ex.Message); Assert.Equal($"Component of type '{typeof(FakeComponent).FullName}' does not have a property matching the name 'SomeUnknownProperty'.", ex.Message);
} }
@ -691,14 +691,14 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert // Act/Assert
var ex = Assert.Throws<InvalidOperationException>(() => var ex = Assert.Throws<InvalidOperationException>(() =>
{ {
diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, oldTree.GetNodes(), newTree.GetNodes()); diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, oldTree.GetFrames(), newTree.GetFrames());
}); });
Assert.StartsWith($"Unable to set property '{nameof(FakeComponent.ReadonlyProperty)}' on " + Assert.StartsWith($"Unable to set property '{nameof(FakeComponent.ReadonlyProperty)}' on " +
$"component of type '{typeof(FakeComponent).FullName}'.", ex.Message); $"component of type '{typeof(FakeComponent).FullName}'.", ex.Message);
} }
[Fact] [Fact]
public void RetainsChildComponentsForExistingNodes() public void RetainsChildComponentsForExistingFrames()
{ {
// Arrange // Arrange
oldTree.AddText(10, "text1"); // 0: text1 oldTree.AddText(10, "text1"); // 0: text1
@ -716,21 +716,21 @@ namespace Microsoft.AspNetCore.Blazor.Test
newTree.CloseElement(); // </FakeComponent2> newTree.CloseElement(); // </FakeComponent2>
newTree.CloseElement(); // </container newTree.CloseElement(); // </container
diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetNodes(), oldTree.GetNodes()); diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetFrames(), oldTree.GetFrames());
var originalFakeComponentInstance = oldTree.GetNodes().Array[2].Component; var originalFakeComponentInstance = oldTree.GetFrames().Array[2].Component;
var originalFakeComponent2Instance = oldTree.GetNodes().Array[3].Component; var originalFakeComponent2Instance = oldTree.GetFrames().Array[3].Component;
// Act // Act
var result = GetSingleUpdatedComponent(); var result = GetSingleUpdatedComponent();
var newNode1 = newTree.GetNodes().Array[2]; var newFrame1 = newTree.GetFrames().Array[2];
var newNode2 = newTree.GetNodes().Array[3]; var newFrame2 = newTree.GetFrames().Array[3];
// Assert // Assert
Assert.Empty(result.Edits); Assert.Empty(result.Edits);
Assert.Equal(0, newNode1.ComponentId); Assert.Equal(0, newFrame1.ComponentId);
Assert.Equal(1, newNode2.ComponentId); Assert.Equal(1, newFrame2.ComponentId);
Assert.Same(originalFakeComponentInstance, newNode1.Component); Assert.Same(originalFakeComponentInstance, newFrame1.Component);
Assert.Same(originalFakeComponent2Instance, newNode2.Component); Assert.Same(originalFakeComponent2Instance, newFrame2.Component);
} }
[Fact] [Fact]
@ -747,13 +747,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
newTree.AddAttribute(14, nameof(FakeComponent.ObjectProperty), objectWillNotChange); newTree.AddAttribute(14, nameof(FakeComponent.ObjectProperty), objectWillNotChange);
newTree.CloseElement(); newTree.CloseElement();
diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetNodes(), oldTree.GetNodes()); diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetFrames(), oldTree.GetFrames());
var originalComponentInstance = (FakeComponent)oldTree.GetNodes().Array[0].Component; var originalComponentInstance = (FakeComponent)oldTree.GetFrames().Array[0].Component;
originalComponentInstance.ObjectProperty = null; // So we can see it doesn't get reassigned originalComponentInstance.ObjectProperty = null; // So we can see it doesn't get reassigned
// Act // Act
var renderBatch = GetRenderedBatch(); var renderBatch = GetRenderedBatch();
var newComponentInstance = (FakeComponent)oldTree.GetNodes().Array[0].Component; var newComponentInstance = (FakeComponent)oldTree.GetFrames().Array[0].Component;
// Assert // Assert
Assert.Equal(2, renderBatch.UpdatedComponents.Count); Assert.Equal(2, renderBatch.UpdatedComponents.Count);
@ -775,7 +775,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(diffForChildComponent.CurrentState, Assert.Collection(diffForChildComponent.CurrentState,
node => AssertNode.Text(node, "Notifications: 1", 0)); frame => AssertFrame.Text(frame, "Notifications: 1", 0));
} }
[Fact] [Fact]
@ -797,11 +797,11 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert 0: Initial render // Act/Assert 0: Initial render
var batch0 = GetRenderedBatch(new RenderTreeBuilder(renderer), oldTree); var batch0 = GetRenderedBatch(new RenderTreeBuilder(renderer), oldTree);
var diffForChildComponent0 = batch0.UpdatedComponents.Array[1]; var diffForChildComponent0 = batch0.UpdatedComponents.Array[1];
var childComponentNode = batch0.UpdatedComponents.Array[0].CurrentState.Array[0]; var childComponentFrame = batch0.UpdatedComponents.Array[0].CurrentState.Array[0];
var childComponentInstance = (HandlePropertiesChangedComponent)childComponentNode.Component; var childComponentInstance = (HandlePropertiesChangedComponent)childComponentFrame.Component;
Assert.Equal(1, childComponentInstance.NotificationsCount); Assert.Equal(1, childComponentInstance.NotificationsCount);
Assert.Collection(diffForChildComponent0.CurrentState, Assert.Collection(diffForChildComponent0.CurrentState,
node => AssertNode.Text(node, "Notifications: 1", 0)); frame => AssertFrame.Text(frame, "Notifications: 1", 0));
// Act/Assert 1: If properties didn't change, we don't notify // Act/Assert 1: If properties didn't change, we don't notify
GetRenderedBatch(oldTree, newTree1); GetRenderedBatch(oldTree, newTree1);
@ -812,7 +812,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
var diffForChildComponent2 = batch2.UpdatedComponents.Array[1]; var diffForChildComponent2 = batch2.UpdatedComponents.Array[1];
Assert.Equal(2, childComponentInstance.NotificationsCount); Assert.Equal(2, childComponentInstance.NotificationsCount);
Assert.Collection(diffForChildComponent2.CurrentState, Assert.Collection(diffForChildComponent2.CurrentState,
node => AssertNode.Text(node, "Notifications: 2", 0)); frame => AssertFrame.Text(frame, "Notifications: 2", 0));
} }
[Fact] [Fact]
@ -828,10 +828,10 @@ namespace Microsoft.AspNetCore.Blazor.Test
newTree.OpenComponentElement<DisposableComponent>(30); // <DisposableComponent> newTree.OpenComponentElement<DisposableComponent>(30); // <DisposableComponent>
newTree.CloseElement(); // </DisposableComponent> newTree.CloseElement(); // </DisposableComponent>
diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetNodes(), oldTree.GetNodes()); diff.ApplyNewRenderTreeVersion(new RenderBatchBuilder(), 0, new RenderTreeBuilder(renderer).GetFrames(), oldTree.GetFrames());
var disposableComponent1 = (DisposableComponent)oldTree.GetNodes().Array[0].Component; var disposableComponent1 = (DisposableComponent)oldTree.GetFrames().Array[0].Component;
var nonDisposableComponent = (NonDisposableComponent)oldTree.GetNodes().Array[1].Component; var nonDisposableComponent = (NonDisposableComponent)oldTree.GetFrames().Array[1].Component;
var disposableComponent2 = (DisposableComponent)oldTree.GetNodes().Array[2].Component; var disposableComponent2 = (DisposableComponent)oldTree.GetFrames().Array[2].Component;
// Act // Act
var renderedBatch = GetRenderedBatch(); var renderedBatch = GetRenderedBatch();
@ -859,7 +859,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
private RenderBatch GetRenderedBatch(RenderTreeBuilder from, RenderTreeBuilder to) private RenderBatch GetRenderedBatch(RenderTreeBuilder from, RenderTreeBuilder to)
{ {
var batchBuilder = new RenderBatchBuilder(); var batchBuilder = new RenderBatchBuilder();
diff.ApplyNewRenderTreeVersion(batchBuilder, 0, from.GetNodes(), to.GetNodes()); diff.ApplyNewRenderTreeVersion(batchBuilder, 0, from.GetFrames(), to.GetFrames());
return batchBuilder.ToBatch(); return batchBuilder.ToBatch();
} }

View File

@ -32,8 +32,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[componentId], Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[componentId],
node => AssertNode.Element(node, "my element", 1), frame => AssertFrame.Element(frame, "my element", 1),
node => AssertNode.Text(node, "some text")); frame => AssertFrame.Text(frame, "some text"));
} }
[Fact] [Fact]
@ -52,16 +52,16 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert // Act/Assert
var componentId = renderer.AssignComponentId(component); var componentId = renderer.AssignComponentId(component);
renderer.RenderNewBatch(componentId); renderer.RenderNewBatch(componentId);
var componentNode = renderer.Batches.Single().RenderTreesByComponentId[componentId] var componentFrame = renderer.Batches.Single().RenderTreesByComponentId[componentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component); .Single(frame => frame.FrameType == RenderTreeFrameType.Component);
var nestedComponentId = componentNode.ComponentId; var nestedComponentId = componentFrame.ComponentId;
// The nested component exists // The nested component exists
Assert.IsType<MessageComponent>(componentNode.Component); Assert.IsType<MessageComponent>(componentFrame.Component);
// The nested component was rendered as part of the batch // The nested component was rendered as part of the batch
Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[nestedComponentId], Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[nestedComponentId],
node => AssertNode.Text(node, "Nested component output")); frame => AssertFrame.Text(frame, "Nested component output"));
} }
[Fact] [Fact]
@ -75,13 +75,13 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert: first render // Act/Assert: first render
renderer.RenderNewBatch(componentId); renderer.RenderNewBatch(componentId);
Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[componentId], Assert.Collection(renderer.Batches.Single().RenderTreesByComponentId[componentId],
node => AssertNode.Text(node, "Initial message")); frame => AssertFrame.Text(frame, "Initial message"));
// Act/Assert: second render // Act/Assert: second render
component.Message = "Modified message"; component.Message = "Modified message";
renderer.RenderNewBatch(componentId); renderer.RenderNewBatch(componentId);
Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[componentId], Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[componentId],
node => AssertNode.Text(node, "Modified message")); frame => AssertFrame.Text(frame, "Modified message"));
} }
[Fact] [Fact]
@ -96,22 +96,22 @@ namespace Microsoft.AspNetCore.Blazor.Test
}); });
var parentComponentId = renderer.AssignComponentId(parentComponent); var parentComponentId = renderer.AssignComponentId(parentComponent);
renderer.RenderNewBatch(parentComponentId); renderer.RenderNewBatch(parentComponentId);
var nestedComponentNode = renderer.Batches.Single().RenderTreesByComponentId[parentComponentId] var nestedComponentFrame = renderer.Batches.Single().RenderTreesByComponentId[parentComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component); .Single(frame => frame.FrameType == RenderTreeFrameType.Component);
var nestedComponent = (MessageComponent)nestedComponentNode.Component; var nestedComponent = (MessageComponent)nestedComponentFrame.Component;
var nestedComponentId = nestedComponentNode.ComponentId; var nestedComponentId = nestedComponentFrame.ComponentId;
// Act/Assert: inital render // Act/Assert: inital render
nestedComponent.Message = "Render 1"; nestedComponent.Message = "Render 1";
renderer.RenderNewBatch(nestedComponentId); renderer.RenderNewBatch(nestedComponentId);
Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[nestedComponentId], Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[nestedComponentId],
node => AssertNode.Text(node, "Render 1")); frame => AssertFrame.Text(frame, "Render 1"));
// Act/Assert: re-render // Act/Assert: re-render
nestedComponent.Message = "Render 2"; nestedComponent.Message = "Render 2";
renderer.RenderNewBatch(nestedComponentId); renderer.RenderNewBatch(nestedComponentId);
Assert.Collection(renderer.Batches[2].RenderTreesByComponentId[nestedComponentId], Assert.Collection(renderer.Batches[2].RenderTreesByComponentId[nestedComponentId],
node => AssertNode.Text(node, "Render 2")); frame => AssertFrame.Text(frame, "Render 2"));
} }
[Fact] [Fact]
@ -128,16 +128,16 @@ namespace Microsoft.AspNetCore.Blazor.Test
var componentId = renderer.AssignComponentId(component); var componentId = renderer.AssignComponentId(component);
renderer.RenderNewBatch(componentId); renderer.RenderNewBatch(componentId);
var (eventHandlerNodeIndex, _) = FirstWithIndex( var (eventHandlerFrameIndex, _) = FirstWithIndex(
renderer.Batches.Single().RenderTreesByComponentId[componentId], renderer.Batches.Single().RenderTreesByComponentId[componentId],
node => node.AttributeValue != null); frame => frame.AttributeValue != null);
// Assert: Event not yet fired // Assert: Event not yet fired
Assert.Null(receivedArgs); Assert.Null(receivedArgs);
// Act/Assert: Event can be fired // Act/Assert: Event can be fired
var eventArgs = new UIEventArgs(); var eventArgs = new UIEventArgs();
renderer.DispatchEvent(componentId, eventHandlerNodeIndex, eventArgs); renderer.DispatchEvent(componentId, eventHandlerFrameIndex, eventArgs);
Assert.Same(eventArgs, receivedArgs); Assert.Same(eventArgs, receivedArgs);
} }
@ -157,24 +157,24 @@ namespace Microsoft.AspNetCore.Blazor.Test
renderer.RenderNewBatch(parentComponentId); renderer.RenderNewBatch(parentComponentId);
// Arrange: Render nested component // Arrange: Render nested component
var nestedComponentNode = renderer.Batches.Single().RenderTreesByComponentId[parentComponentId] var nestedComponentFrame = renderer.Batches.Single().RenderTreesByComponentId[parentComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component); .Single(frame => frame.FrameType == RenderTreeFrameType.Component);
var nestedComponent = (EventComponent)nestedComponentNode.Component; var nestedComponent = (EventComponent)nestedComponentFrame.Component;
nestedComponent.Handler = args => { receivedArgs = args; }; nestedComponent.Handler = args => { receivedArgs = args; };
var nestedComponentId = nestedComponentNode.ComponentId; var nestedComponentId = nestedComponentFrame.ComponentId;
renderer.RenderNewBatch(nestedComponentId); renderer.RenderNewBatch(nestedComponentId);
// Find nested component's event handler ndoe // Find nested component's event handler ndoe
var (eventHandlerNodeIndex, _) = FirstWithIndex( var (eventHandlerFrameIndex, _) = FirstWithIndex(
renderer.Batches[1].RenderTreesByComponentId[nestedComponentId], renderer.Batches[1].RenderTreesByComponentId[nestedComponentId],
node => node.AttributeValue != null); frame => frame.AttributeValue != null);
// Assert: Event not yet fired // Assert: Event not yet fired
Assert.Null(receivedArgs); Assert.Null(receivedArgs);
// Act/Assert: Event can be fired // Act/Assert: Event can be fired
var eventArgs = new UIEventArgs(); var eventArgs = new UIEventArgs();
renderer.DispatchEvent(nestedComponentId, eventHandlerNodeIndex, eventArgs); renderer.DispatchEvent(nestedComponentId, eventHandlerFrameIndex, eventArgs);
Assert.Same(eventArgs, receivedArgs); Assert.Same(eventArgs, receivedArgs);
} }
@ -314,7 +314,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var nestedComponentInstance = (MessageComponent)renderer.Batches.Single().RenderTreesByComponentId[rootComponentId] var nestedComponentInstance = (MessageComponent)renderer.Batches.Single().RenderTreesByComponentId[rootComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component) .Single(frame => frame.FrameType == RenderTreeFrameType.Component)
.Component; .Component;
// Act: Second render // Act: Second render
@ -323,8 +323,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Assert // Assert
Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[rootComponentId], Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[rootComponentId],
node => AssertNode.Text(node, "Modified message"), frame => AssertFrame.Text(frame, "Modified message"),
node => Assert.Same(nestedComponentInstance, node.Component)); frame => Assert.Same(nestedComponentInstance, frame.Component));
} }
[Fact] [Fact]
@ -347,7 +347,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var originalComponentInstance = (FakeComponent)renderer.Batches.Single().RenderTreesByComponentId[rootComponentId] var originalComponentInstance = (FakeComponent)renderer.Batches.Single().RenderTreesByComponentId[rootComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component) .Single(frame => frame.FrameType == RenderTreeFrameType.Component)
.Component; .Component;
// Assert 1: properties were assigned // Assert 1: properties were assigned
@ -360,7 +360,7 @@ namespace Microsoft.AspNetCore.Blazor.Test
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var updatedComponentInstance = (FakeComponent)renderer.Batches[1].RenderTreesByComponentId[rootComponentId] var updatedComponentInstance = (FakeComponent)renderer.Batches[1].RenderTreesByComponentId[rootComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component) .Single(frame => frame.FrameType == RenderTreeFrameType.Component)
.Component; .Component;
// Assert // Assert
@ -387,19 +387,19 @@ namespace Microsoft.AspNetCore.Blazor.Test
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var childComponentId = renderer.Batches.Single().RenderTreesByComponentId[rootComponentId] var childComponentId = renderer.Batches.Single().RenderTreesByComponentId[rootComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component) .Single(frame => frame.FrameType == RenderTreeFrameType.Component)
.ComponentId; .ComponentId;
// Act: Second render // Act: Second render
firstRender = false; firstRender = false;
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var updatedComponentNode = renderer.Batches[1].RenderTreesByComponentId[rootComponentId] var updatedComponentFrame = renderer.Batches[1].RenderTreesByComponentId[rootComponentId]
.Single(node => node.NodeType == RenderTreeNodeType.Component); .Single(frame => frame.FrameType == RenderTreeFrameType.Component);
// Assert // Assert
Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[updatedComponentNode.ComponentId], Assert.Collection(renderer.Batches[1].RenderTreesByComponentId[updatedComponentFrame.ComponentId],
node => AssertNode.Text(node, "second")); frame => AssertFrame.Text(frame, "second"));
} }
[Fact] [Fact]
@ -428,8 +428,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
// Act/Assert 1: First render, capturing child component IDs // Act/Assert 1: First render, capturing child component IDs
renderer.RenderNewBatch(rootComponentId); renderer.RenderNewBatch(rootComponentId);
var childComponentIds = renderer.Batches.Single().RenderTreesByComponentId[rootComponentId] var childComponentIds = renderer.Batches.Single().RenderTreesByComponentId[rootComponentId]
.Where(node => node.NodeType == RenderTreeNodeType.Component) .Where(frame => frame.FrameType == RenderTreeFrameType.Component)
.Select(node => node.ComponentId) .Select(frame => frame.ComponentId)
.ToList(); .ToList();
Assert.Equal(childComponentIds, new[] { 1, 2, 3 }); Assert.Equal(childComponentIds, new[] { 1, 2, 3 });
@ -486,8 +486,8 @@ namespace Microsoft.AspNetCore.Blazor.Test
private class CapturedBatch private class CapturedBatch
{ {
public IDictionary<int, RenderTreeNode[]> RenderTreesByComponentId { get; } public IDictionary<int, RenderTreeFrame[]> RenderTreesByComponentId { get; }
= new Dictionary<int, RenderTreeNode[]>(); = new Dictionary<int, RenderTreeFrame[]>();
public IList<int> DisposedComponentIDs { get; set; } public IList<int> DisposedComponentIDs { get; set; }
} }

View File

@ -0,0 +1,70 @@
// 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;
using Microsoft.AspNetCore.Blazor.Components;
using Microsoft.AspNetCore.Blazor.RenderTree;
using Xunit;
namespace Microsoft.AspNetCore.Blazor.Test.Shared
{
internal static class AssertFrame
{
public static void Sequence(RenderTreeFrame frame, int? sequence = null)
{
if (sequence.HasValue)
{
Assert.Equal(sequence.Value, frame.Sequence);
}
}
public static void Text(RenderTreeFrame frame, string textContent, int? sequence = null)
{
Assert.Equal(RenderTreeFrameType.Text, frame.FrameType);
Assert.Equal(textContent, frame.TextContent);
Assert.Equal(0, frame.ElementDescendantsEndIndex);
AssertFrame.Sequence(frame, sequence);
}
public static void Element(RenderTreeFrame frame, string elementName, int descendantsEndIndex, int? sequence = null)
{
Assert.Equal(RenderTreeFrameType.Element, frame.FrameType);
Assert.Equal(elementName, frame.ElementName);
Assert.Equal(descendantsEndIndex, frame.ElementDescendantsEndIndex);
AssertFrame.Sequence(frame, sequence);
}
public static void Attribute(RenderTreeFrame frame, string attributeName, int? sequence = null)
{
Assert.Equal(RenderTreeFrameType.Attribute, frame.FrameType);
Assert.Equal(attributeName, frame.AttributeName);
AssertFrame.Sequence(frame, sequence);
}
public static void Attribute(RenderTreeFrame frame, string attributeName, string attributeValue, int? sequence = null)
{
AssertFrame.Attribute(frame, attributeName, sequence);
Assert.Equal(attributeValue, frame.AttributeValue);
}
public static void Attribute(RenderTreeFrame frame, string attributeName, UIEventHandler attributeEventHandlerValue, int? sequence = null)
{
AssertFrame.Attribute(frame, attributeName, sequence);
Assert.Equal(attributeEventHandlerValue, frame.AttributeValue);
}
public static void Component<T>(RenderTreeFrame frame, int? sequence = null) where T : IComponent
{
Assert.Equal(RenderTreeFrameType.Component, frame.FrameType);
Assert.Equal(typeof(T), frame.ComponentType);
AssertFrame.Sequence(frame, sequence);
}
public static void Whitespace(RenderTreeFrame frame, int? sequence = null)
{
Assert.Equal(RenderTreeFrameType.Text, frame.FrameType);
AssertFrame.Sequence(frame, sequence);
Assert.True(string.IsNullOrWhiteSpace(frame.TextContent));
}
}
}

View File

@ -1,70 +0,0 @@
// 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;
using Microsoft.AspNetCore.Blazor.Components;
using Microsoft.AspNetCore.Blazor.RenderTree;
using Xunit;
namespace Microsoft.AspNetCore.Blazor.Test.Shared
{
internal static class AssertNode
{
public static void Sequence(RenderTreeNode node, int? sequence = null)
{
if (sequence.HasValue)
{
Assert.Equal(sequence.Value, node.Sequence);
}
}
public static void Text(RenderTreeNode node, string textContent, int? sequence = null)
{
Assert.Equal(RenderTreeNodeType.Text, node.NodeType);
Assert.Equal(textContent, node.TextContent);
Assert.Equal(0, node.ElementDescendantsEndIndex);
AssertNode.Sequence(node, sequence);
}
public static void Element(RenderTreeNode node, string elementName, int descendantsEndIndex, int? sequence = null)
{
Assert.Equal(RenderTreeNodeType.Element, node.NodeType);
Assert.Equal(elementName, node.ElementName);
Assert.Equal(descendantsEndIndex, node.ElementDescendantsEndIndex);
AssertNode.Sequence(node, sequence);
}
public static void Attribute(RenderTreeNode node, string attributeName, int? sequence = null)
{
Assert.Equal(RenderTreeNodeType.Attribute, node.NodeType);
Assert.Equal(attributeName, node.AttributeName);
AssertNode.Sequence(node, sequence);
}
public static void Attribute(RenderTreeNode node, string attributeName, string attributeValue, int? sequence = null)
{
AssertNode.Attribute(node, attributeName, sequence);
Assert.Equal(attributeValue, node.AttributeValue);
}
public static void Attribute(RenderTreeNode node, string attributeName, UIEventHandler attributeEventHandlerValue, int? sequence = null)
{
AssertNode.Attribute(node, attributeName, sequence);
Assert.Equal(attributeEventHandlerValue, node.AttributeValue);
}
public static void Component<T>(RenderTreeNode node, int? sequence = null) where T : IComponent
{
Assert.Equal(RenderTreeNodeType.Component, node.NodeType);
Assert.Equal(typeof(T), node.ComponentType);
AssertNode.Sequence(node, sequence);
}
public static void Whitespace(RenderTreeNode node, int? sequence = null)
{
Assert.Equal(RenderTreeNodeType.Text, node.NodeType);
AssertNode.Sequence(node, sequence);
Assert.True(string.IsNullOrWhiteSpace(node.TextContent));
}
}
}