Skip to content

Commit

Permalink
Cleanups and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
javiercn committed Apr 17, 2023
1 parent 4976961 commit 43db13f
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 24 deletions.
4 changes: 2 additions & 2 deletions src/Components/Components/src/Binding/CascadingModelBinder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CascadingModelBinder : IComponent
/// <summary>
/// The binding context name.
/// </summary>
[Parameter] public string BindingId { get; set; } = default!;
[Parameter] public string BindingContextId { get; set; } = default!;

/// <summary>
/// Specifies the content to be rendered inside this <see cref="CascadingModelBinder"/>.
Expand All @@ -49,7 +49,7 @@ Task IComponent.SetParametersAsync(ParameterView parameters)
}

var name = string.IsNullOrEmpty(ParentContext?.Name) ? Name : $"{ParentContext.Name}.{Name}";
var bindingId = !string.IsNullOrEmpty(name) ? null : BindingId;
var bindingId = !string.IsNullOrEmpty(name) ? null : BindingContextId;
_bindingContext = new ModelBindingContext(name, bindingId);

_handle.Render(builder =>
Expand Down
6 changes: 3 additions & 3 deletions src/Components/Components/src/Binding/ModelBindingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class ModelBindingContext
// Nested named binder
// Name = <<parent>>.<<handler>>
// FormAction = ?handler=<<parent>>.<<handler>>
public ModelBindingContext(string name, string? bindingId = null)
internal ModelBindingContext(string name, string? bindingId = null)
{
// We are initializing the root context, that can be a "named" root context, or the default context.
// A named root context only provides a name, and that acts as the BindingId
Expand All @@ -35,7 +35,7 @@ public ModelBindingContext(string name, string? bindingId = null)
}

Name = name;
BindingId = bindingId ?? name;
BindingContextId = bindingId ?? name;
}

/// <summary>
Expand All @@ -46,5 +46,5 @@ public ModelBindingContext(string name, string? bindingId = null)
/// <summary>
/// The computed identifier used to determine what parts of the app can bind data.
/// </summary>
public string BindingId { get; }
public string BindingContextId { get; }
}
7 changes: 4 additions & 3 deletions src/Components/Components/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#nullable enable
Microsoft.AspNetCore.Components.Binding.ModelBindingContext
Microsoft.AspNetCore.Components.Binding.ModelBindingContext.ModelBindingContext(string! name) -> void
Microsoft.AspNetCore.Components.Binding.ModelBindingContext.BindingContextId.get -> string!
Microsoft.AspNetCore.Components.Binding.ModelBindingContext.Name.get -> string!
Microsoft.AspNetCore.Components.CascadingModelBinder
Microsoft.AspNetCore.Components.CascadingModelBinder.BindingContextId.get -> string!
Microsoft.AspNetCore.Components.CascadingModelBinder.BindingContextId.set -> void
Microsoft.AspNetCore.Components.CascadingModelBinder.CascadingModelBinder() -> void
Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.get -> Microsoft.AspNetCore.Components.RenderFragment!
Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.get -> Microsoft.AspNetCore.Components.RenderFragment<Microsoft.AspNetCore.Components.Binding.ModelBindingContext!>!
Microsoft.AspNetCore.Components.CascadingModelBinder.ChildContent.set -> void
Microsoft.AspNetCore.Components.CascadingModelBinder.Name.get -> string!
Microsoft.AspNetCore.Components.CascadingModelBinder.Name.set -> void
Expand All @@ -13,7 +15,6 @@ Microsoft.AspNetCore.Components.Infrastructure.ComponentStatePersistenceManager.
Microsoft.AspNetCore.Components.RenderHandle.DispatchExceptionAsync(System.Exception! exception) -> System.Threading.Tasks.Task!
*REMOVED*Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string! relativeUri) -> System.Uri!
Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string? relativeUri) -> System.Uri!
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, Microsoft.AspNetCore.Components.RenderFragment? value) -> void
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.SetEventHandlerName(string! eventHandlerName) -> void
Microsoft.AspNetCore.Components.Routing.IScrollToLocationHash
Microsoft.AspNetCore.Components.Routing.IScrollToLocationHash.RefreshScrollPositionForHash(string! locationAbsolute) -> System.Threading.Tasks.Task!
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Components/src/RouteView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ private void RenderPageWithParameters(RenderTreeBuilder builder)

builder.OpenComponent<CascadingModelBinder>(0);
builder.AddComponentParameter(1, nameof(CascadingModelBinder.Name), "");
builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingId), bindingId);
builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingContextId), bindingId);
builder.AddComponentParameter(3, nameof(CascadingModelBinder.ChildContent), (RenderFragment<ModelBindingContext>)RenderPageWithContext);
builder.CloseComponent();

Expand Down
18 changes: 9 additions & 9 deletions src/Components/Components/test/RenderTreeDiffBuilderTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,7 @@ public void RecognizesComponentTypeChangesAtSameSequenceNumber()
using var batchBuilder = new RenderBatchBuilder();

// Act
var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, newTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), newTree.GetFrames(), newTree.GetNamedEvents());

// Assert: We're going to dispose the old component and render the new one
Assert.Equal(new[] { 0 }, batchBuilder.ComponentDisposalQueue);
Expand Down Expand Up @@ -1627,7 +1627,7 @@ public void RetainsChildComponentsForExistingFrames()

using var batchBuilder = new RenderBatchBuilder();
using var renderTreeBuilder = new RenderTreeBuilder();
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTreeBuilder.GetFrames(), renderTreeBuilder.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
var originalFakeComponentInstance = oldTree.GetFrames().Array[2].Component;
var originalFakeComponent2Instance = oldTree.GetFrames().Array[3].Component;

Expand Down Expand Up @@ -1713,7 +1713,7 @@ public void SetsUpdatedParametersOnChildComponents()

using var batchBuilder = new RenderBatchBuilder();
using var renderTree = new RenderTreeBuilder();
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTree.GetFrames(), renderTree.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
var originalComponentInstance = (FakeComponent)oldTree.GetFrames().Array[0].Component;

// Act
Expand Down Expand Up @@ -1763,7 +1763,7 @@ public void SkipsUpdatingParametersOnChildComponentsIfAllAreDefinitelyImmutableA

using var batchBuilder = new RenderBatchBuilder();
using var renderTreeBuilder = new RenderTreeBuilder();
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTreeBuilder.GetFrames(), renderTreeBuilder.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
var originalComponentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[0].Component;
Assert.Equal(1, originalComponentInstance.SetParametersCallCount);

Expand Down Expand Up @@ -1793,7 +1793,7 @@ public void AlwaysRegardsRenderFragmentAsPossiblyChanged()

using var batchBuilder = new RenderBatchBuilder();
using var renderTreeBuilder = new RenderTreeBuilder();
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), renderTreeBuilder.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTreeBuilder.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
var componentInstance = (CaptureSetParametersComponent)oldTree.GetFrames().Array[0].Component;
Assert.Equal(1, componentInstance.SetParametersCallCount);

Expand All @@ -1819,13 +1819,13 @@ public void QueuesRemovedChildComponentsForDisposal()

using var batchBuilder = new RenderBatchBuilder();
using var renderTree = new RenderTreeBuilder();
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), renderTree.GetFrames(), renderTree.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, renderTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());

// Act/Assert
// Note that we track NonDisposableComponent was disposed even though it's not IDisposable,
// because it's up to the upstream renderer to decide what "disposing" a component means
Assert.Empty(batchBuilder.ComponentDisposalQueue);
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, newTree.GetFrames(), oldTree.GetFrames(), oldTree.GetNamedEvents());
RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, oldTree.GetFrames(), newTree.GetFrames(), newTree.GetNamedEvents());
Assert.Equal(new[] { 0, 1 }, batchBuilder.ComponentDisposalQueue);
}

Expand Down Expand Up @@ -2238,14 +2238,14 @@ private RenderBatch GetRenderedBatch(RenderTreeBuilder from, RenderTreeBuilder t
var emptyFrames = renderTreeBuilder.GetFrames();
var oldFrames = from.GetFrames();

RenderTreeDiffBuilder.ComputeDiff(renderer, initializeBatchBuilder, 0, oldFrames, emptyFrames, null);
RenderTreeDiffBuilder.ComputeDiff(renderer, initializeBatchBuilder, 0, emptyFrames, oldFrames, from.GetNamedEvents());
}

batchBuilder?.Dispose();
// This gets disposed as part of the test type's Dispose
batchBuilder = new RenderBatchBuilder();

var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, to.GetFrames(), from.GetFrames(), from.GetNamedEvents());
var diff = RenderTreeDiffBuilder.ComputeDiff(renderer, batchBuilder, 0, from.GetFrames(), to.GetFrames(), to.GetNamedEvents());
batchBuilder.UpdatedComponentDiffs.Append(diff);
return batchBuilder.ToBatch();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Components/test/RouteViewTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void RendersPageInsideLayoutView()
frame => AssertFrame.Region(frame, subtreeLength: 5),
frame => AssertFrame.Component<CascadingModelBinder>(frame, sequence: 0, subtreeLength: 4),
frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.Name), "", sequence: 1),
frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.BindingId), "jan", sequence: 2),
frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.BindingContextId), "jan", sequence: 2),
frame => AssertFrame.Attribute(frame, nameof(CascadingModelBinder.ChildContent), typeof(RenderFragment<ModelBindingContext>), sequence: 3),
frame => AssertFrame.Text(frame, "Layout ends here", sequence: 2));

Expand Down
2 changes: 1 addition & 1 deletion src/Components/Endpoints/src/RazorComponentEndpointHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ private void BuildRenderTree(RenderTreeBuilder builder)

builder.OpenComponent<LayoutView>(0);
builder.AddComponentParameter(1, nameof(LayoutView.Layout), pageLayoutType);
builder.AddComponentParameter(2, nameof(LayoutView.ChildContent), RenderPageWithParameters);
builder.AddComponentParameter(2, nameof(LayoutView.ChildContent), (RenderFragment)RenderPageWithParameters);
builder.CloseComponent();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Web/src/Forms/EditForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public EditContext? EditContext
/// The <c>name</c> attribute on the <c>form</c> element will default to
/// the <see cref="FormHandlerName"/> unless an explicit name is provided.
/// </remarks>
[Parameter] public string FormHandlerName { get; set; }
[Parameter] public string? FormHandlerName { get; set; }

/// <inheritdoc />
protected override void OnParametersSet()
Expand Down Expand Up @@ -165,7 +165,7 @@ void RenderFormContents(RenderTreeBuilder builder, ModelBindingContext? bindingC
builder.AddAttribute(4, "onsubmit", _handleSubmitDelegate);
if (bindingContext != null)
{
builder.SetEventHandlerName(bindingContext.BindingId);
builder.SetEventHandlerName(bindingContext.BindingContextId);
}
builder.OpenComponent<CascadingValue<EditContext>>(5);
builder.AddComponentParameter(6, "IsFixed", true);
Expand Down
2 changes: 2 additions & 0 deletions src/Components/Web/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
*REMOVED*override Microsoft.AspNetCore.Components.Forms.InputFile.OnInitialized() -> void
Microsoft.AspNetCore.Components.Forms.EditForm.BindingContext.get -> Microsoft.AspNetCore.Components.Binding.ModelBindingContext?
Microsoft.AspNetCore.Components.Forms.EditForm.BindingContext.set -> void
Microsoft.AspNetCore.Components.Forms.EditForm.FormHandlerName.get -> string?
Microsoft.AspNetCore.Components.Forms.EditForm.FormHandlerName.set -> void
Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer
Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.BeginRenderingComponent(System.Type! componentType, Microsoft.AspNetCore.Components.ParameterView initialParameters) -> Microsoft.AspNetCore.Components.Web.HtmlRendering.HtmlRootComponent
Microsoft.AspNetCore.Components.HtmlRendering.Infrastructure.StaticHtmlRenderer.StaticHtmlRenderer(System.IServiceProvider! serviceProvider, Microsoft.Extensions.Logging.ILoggerFactory! loggerFactory) -> void
Expand Down
4 changes: 2 additions & 2 deletions src/Components/Web/test/Forms/EditFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenComponent<CascadingModelBinder>(0);
builder.AddComponentParameter(1, nameof(CascadingModelBinder.Name), BindingContext.Name);
builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingId), BindingContext.BindingId);
builder.AddComponentParameter<ModelBindingContext>(3, nameof(CascadingModelBinder.ChildContent), (_) => RenderForm);
builder.AddComponentParameter(2, nameof(CascadingModelBinder.BindingContextId), BindingContext.BindingContextId);
builder.AddComponentParameter(3, nameof(CascadingModelBinder.ChildContent), (RenderFragment<ModelBindingContext>)((_) => RenderForm));
builder.CloseComponent();
}
else
Expand Down

0 comments on commit 43db13f

Please sign in to comment.