Skip to content

API review followups #50181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ public static class CascadingValueServiceCollectionExtensions
/// </summary>
/// <typeparam name="TValue">The value type.</typeparam>
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
/// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
/// <param name="initialValueFactory">A callback that supplies a fixed value within each service provider scope.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddCascadingValue<TValue>(
this IServiceCollection serviceCollection, Func<IServiceProvider, TValue> valueFactory)
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(() => valueFactory(sp), isFixed: true));
this IServiceCollection serviceCollection, Func<IServiceProvider, TValue> initialValueFactory)
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(() => initialValueFactory(sp), isFixed: true));

/// <summary>
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having
Expand All @@ -30,11 +30,11 @@ public static IServiceCollection AddCascadingValue<TValue>(
/// <typeparam name="TValue">The value type.</typeparam>
/// <param name="serviceCollection">The <see cref="IServiceCollection"/>.</param>
/// <param name="name">A name for the cascading value. If set, <see cref="CascadingParameterAttribute"/> can be configured to match based on this name.</param>
/// <param name="valueFactory">A callback that supplies a fixed value within each service provider scope.</param>
/// <param name="initialValueFactory">A callback that supplies a fixed value within each service provider scope.</param>
/// <returns>The <see cref="IServiceCollection"/>.</returns>
public static IServiceCollection AddCascadingValue<TValue>(
this IServiceCollection serviceCollection, string name, Func<IServiceProvider, TValue> valueFactory)
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(name, () => valueFactory(sp), isFixed: true));
this IServiceCollection serviceCollection, string name, Func<IServiceProvider, TValue> initialValueFactory)
=> serviceCollection.AddScoped<ICascadingValueSupplier>(sp => new CascadingValueSource<TValue>(name, () => initialValueFactory(sp), isFixed: true));

/// <summary>
/// Adds a cascading value to the <paramref name="serviceCollection"/>. This is equivalent to having
Expand Down
10 changes: 5 additions & 5 deletions src/Components/Components/src/CascadingValueSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,20 @@ public CascadingValueSource(string name, TValue value, bool isFixed) : this(valu
/// <summary>
/// Constructs an instance of <see cref="CascadingValueSource{TValue}"/>.
/// </summary>
/// <param name="valueFactory">A callback that produces the initial value when first required.</param>
/// <param name="initialValueFactory">A callback that produces the initial value when first required.</param>
/// <param name="isFixed">A flag to indicate whether the value is fixed. If false, all receipients will subscribe for update notifications, which you can issue by calling <see cref="NotifyChangedAsync()"/>. These subscriptions come at a performance cost, so if the value will not change, set <paramref name="isFixed"/> to true.</param>
public CascadingValueSource(Func<TValue> valueFactory, bool isFixed) : this(isFixed)
public CascadingValueSource(Func<TValue> initialValueFactory, bool isFixed) : this(isFixed)
{
_initialValueFactory = valueFactory;
_initialValueFactory = initialValueFactory;
}

/// <summary>
/// Constructs an instance of <see cref="CascadingValueSource{TValue}"/>.
/// </summary>
/// <param name="name">A name for the cascading value. If set, <see cref="CascadingParameterAttribute"/> can be configured to match based on this name.</param>
/// <param name="valueFactory">A callback that produces the initial value when first required.</param>
/// <param name="initialValueFactory">A callback that produces the initial value when first required.</param>
/// <param name="isFixed">A flag to indicate whether the value is fixed. If false, all receipients will subscribe for update notifications, which you can issue by calling <see cref="NotifyChangedAsync()"/>. These subscriptions come at a performance cost, so if the value will not change, set <paramref name="isFixed"/> to true.</param>
public CascadingValueSource(string name, Func<TValue> valueFactory, bool isFixed) : this(valueFactory, isFixed)
public CascadingValueSource(string name, Func<TValue> initialValueFactory, bool isFixed) : this(initialValueFactory, isFixed)
{
ArgumentNullException.ThrowIfNull(name);
_name = name;
Expand Down
14 changes: 7 additions & 7 deletions src/Components/Components/src/PublicAPI.Unshipped.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ Microsoft.AspNetCore.Components.CascadingParameterInfo.CascadingParameterInfo()
Microsoft.AspNetCore.Components.CascadingParameterInfo.PropertyName.get -> string!
Microsoft.AspNetCore.Components.CascadingParameterInfo.PropertyType.get -> System.Type!
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, System.Func<TValue>! valueFactory, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, System.Func<TValue>! initialValueFactory, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(string! name, TValue value, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(System.Func<TValue>! valueFactory, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(System.Func<TValue>! initialValueFactory, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.CascadingValueSource(TValue value, bool isFixed) -> void
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.NotifyChangedAsync() -> System.Threading.Tasks.Task!
Microsoft.AspNetCore.Components.CascadingValueSource<TValue>.NotifyChangedAsync(TValue newValue) -> System.Threading.Tasks.Task!
Expand All @@ -24,10 +24,10 @@ Microsoft.AspNetCore.Components.RenderHandle.DispatchExceptionAsync(System.Excep
Microsoft.AspNetCore.Components.NavigationManager.ToAbsoluteUri(string? relativeUri) -> System.Uri!
Microsoft.AspNetCore.Components.Rendering.ComponentState.LogicalParentComponentState.get -> Microsoft.AspNetCore.Components.Rendering.ComponentState?
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentRenderMode(int sequence, Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
*REMOVED*Microsoft.AspNetCore.Components.RouteData.RouteData(System.Type! pageType, System.Collections.Generic.IReadOnlyDictionary<string!, object!>! routeValues) -> void
*REMOVED*Microsoft.AspNetCore.Components.RouteData.RouteValues.get -> System.Collections.Generic.IReadOnlyDictionary<string!, object!>!
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddNamedEvent(int sequence, string! eventType, string! assignedName) -> void
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentRenderMode(Microsoft.AspNetCore.Components.IComponentRenderMode! renderMode) -> void
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddNamedEvent(string! eventType, string! assignedName) -> void
Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags
Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags.HasCallerSpecifiedRenderMode = 1 -> Microsoft.AspNetCore.Components.RenderTree.ComponentFrameFlags
Microsoft.AspNetCore.Components.RenderTree.NamedEventChange
Expand Down Expand Up @@ -80,17 +80,17 @@ Microsoft.AspNetCore.Components.Sections.SectionOutlet.SectionOutlet() -> void
Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder.AddComponentParameter(int sequence, string! name, object? value) -> void
Microsoft.AspNetCore.Components.StreamRenderingAttribute
Microsoft.AspNetCore.Components.StreamRenderingAttribute.Enabled.get -> bool
Microsoft.AspNetCore.Components.StreamRenderingAttribute.StreamRenderingAttribute(bool enabled) -> void
Microsoft.AspNetCore.Components.StreamRenderingAttribute.StreamRenderingAttribute(bool enabled = true) -> void
Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions
Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions
override Microsoft.AspNetCore.Components.EventCallback.GetHashCode() -> int
override Microsoft.AspNetCore.Components.EventCallback.Equals(object? obj) -> bool
override Microsoft.AspNetCore.Components.EventCallback<TValue>.GetHashCode() -> int
override Microsoft.AspNetCore.Components.EventCallback<TValue>.Equals(object? obj) -> bool
static Microsoft.AspNetCore.Components.SupplyParameterFromQueryProviderServiceCollectionExtensions.AddSupplyValueFromQueryProvider(this Microsoft.Extensions.DependencyInjection.IServiceCollection! services) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! initialValueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, Microsoft.AspNetCore.Components.CascadingValueSource<TValue>!>! sourceFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.AddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! initialValueFactory) -> Microsoft.Extensions.DependencyInjection.IServiceCollection!
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, string! name, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> void
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, Microsoft.AspNetCore.Components.CascadingValueSource<TValue>!>! sourceFactory) -> void
static Microsoft.Extensions.DependencyInjection.CascadingValueServiceCollectionExtensions.TryAddCascadingValue<TValue>(this Microsoft.Extensions.DependencyInjection.IServiceCollection! serviceCollection, System.Func<System.IServiceProvider!, TValue>! valueFactory) -> void
Expand Down
2 changes: 1 addition & 1 deletion src/Components/Components/src/RenderModeAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace Microsoft.AspNetCore.Components;
/// be implemented to work across all render modes. Component authors should only specify
/// a fixed rendering mode when the component is incapable of running in other modes.
/// </summary>
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
public abstract class RenderModeAttribute : Attribute
{
/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public void AppendRegion(int sequence)
};
}

public void AppendComponentRenderMode(int sequence, IComponentRenderMode renderMode)
public void AppendComponentRenderMode(IComponentRenderMode renderMode)
{
if (_itemsInUse == _items.Length)
{
Expand All @@ -144,13 +144,13 @@ public void AppendComponentRenderMode(int sequence, IComponentRenderMode renderM

_items[_itemsInUse++] = new RenderTreeFrame
{
SequenceField = sequence,
SequenceField = 0, // We're only interested in one of these, so it's not useful to optimize diffing over multiple
FrameTypeField = RenderTreeFrameType.ComponentRenderMode,
ComponentRenderModeField = renderMode,
};
}

public void AppendNamedEvent(int sequence, string eventType, string assignedName)
public void AppendNamedEvent(string eventType, string assignedName)
{
if (_itemsInUse == _items.Length)
{
Expand All @@ -159,7 +159,7 @@ public void AppendNamedEvent(int sequence, string eventType, string assignedName

_items[_itemsInUse++] = new RenderTreeFrame
{
SequenceField = sequence,
SequenceField = 0, // We're only interested in one of these per eventType, so it's not useful to optimize diffing over multiple
FrameTypeField = RenderTreeFrameType.NamedEvent,
NamedEventTypeField = eventType,
NamedEventAssignedNameField = assignedName,
Expand Down
20 changes: 9 additions & 11 deletions src/Components/Components/src/Rendering/RenderTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class RenderTreeBuilder : IDisposable
private bool _hasSeenAddMultipleAttributes;
private Dictionary<string, int>? _seenAttributeNames;
private IComponentRenderMode? _pendingComponentCallSiteRenderMode; // TODO: Remove when Razor compiler supports call-site @rendermode
private (int Sequence, string AssignedName)? _pendingNamedSubmitEvent; // TODO: Remove when Razor compiler supports @formname
private string? _pendingNamedSubmitEvent; // TODO: Remove when Razor compiler supports @formname

/// <summary>
/// The reserved parameter name used for supplying child content.
Expand Down Expand Up @@ -83,9 +83,9 @@ public void CloseElement()
// TODO: Remove this once Razor supports @formname
private void CompletePendingNamedSubmitEvent()
{
if (_pendingNamedSubmitEvent is { } pendingNamedSubmitEvent)
if (_pendingNamedSubmitEvent is not null)
{
AddNamedEvent(pendingNamedSubmitEvent.Sequence, "onsubmit", pendingNamedSubmitEvent.AssignedName);
AddNamedEvent("onsubmit", _pendingNamedSubmitEvent);
_pendingNamedSubmitEvent = default;
}
}
Expand Down Expand Up @@ -241,7 +241,7 @@ public void AddAttribute(int sequence, string name, string? value)
// That should compile directly as a call to AddNamedEvent.
if (string.Equals(name, "@formname", StringComparison.Ordinal) && _lastNonAttributeFrameType == RenderTreeFrameType.Element)
{
_pendingNamedSubmitEvent = (sequence, value!);
_pendingNamedSubmitEvent = value!;
}
else
{
Expand Down Expand Up @@ -623,7 +623,7 @@ public void CloseComponent()
{
if (_pendingComponentCallSiteRenderMode is not null)
{
AddComponentRenderMode(0, _pendingComponentCallSiteRenderMode);
AddComponentRenderMode(_pendingComponentCallSiteRenderMode);
_pendingComponentCallSiteRenderMode = null;
}

Expand Down Expand Up @@ -681,9 +681,8 @@ public void AddComponentReferenceCapture(int sequence, Action<object> componentR
/// <summary>
/// Adds a frame indicating the render mode on the enclosing component frame.
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="renderMode">The <see cref="IComponentRenderMode"/>.</param>
public void AddComponentRenderMode(int sequence, IComponentRenderMode renderMode)
public void AddComponentRenderMode(IComponentRenderMode renderMode)
{
ArgumentNullException.ThrowIfNull(renderMode);

Expand All @@ -709,17 +708,16 @@ public void AddComponentRenderMode(int sequence, IComponentRenderMode renderMode

parentFrame.ComponentFrameFlagsField |= ComponentFrameFlags.HasCallerSpecifiedRenderMode;

_entries.AppendComponentRenderMode(sequence, renderMode);
_entries.AppendComponentRenderMode(renderMode);
_lastNonAttributeFrameType = RenderTreeFrameType.ComponentRenderMode;
}

/// <summary>
/// Assigns a name to an event in the enclosing element.
/// </summary>
/// <param name="sequence">An integer that represents the position of the instruction in the source code.</param>
/// <param name="eventType">The event type, e.g., 'onsubmit'.</param>
/// <param name="assignedName">The application-assigned name.</param>
public void AddNamedEvent(int sequence, string eventType, string assignedName)
public void AddNamedEvent(string eventType, string assignedName)
{
ArgumentNullException.ThrowIfNull(eventType);
ArgumentException.ThrowIfNullOrEmpty(assignedName);
Expand All @@ -733,7 +731,7 @@ public void AddNamedEvent(int sequence, string eventType, string assignedName)
throw new InvalidOperationException($"Named events may only be added as children of frames of type {RenderTreeFrameType.Element}");
}

_entries.AppendNamedEvent(sequence, eventType, assignedName);
_entries.AppendNamedEvent(eventType, assignedName);
_lastNonAttributeFrameType = RenderTreeFrameType.NamedEvent;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Components/Components/src/StreamRenderingAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class StreamRenderingAttribute : Attribute
/// <summary>
/// Constructs an instance of <see cref="StreamRenderingAttribute"/>
/// </summary>
/// <param name="enabled">A flag to indicate whether this component and its descendants should stream their rendering.</param>
public StreamRenderingAttribute(bool enabled)
/// <param name="enabled">A flag to indicate whether this component and its descendants should stream their rendering. The default value is true.</param>
public StreamRenderingAttribute(bool enabled = true)
{
Enabled = enabled;
}
Expand Down
Loading