Skip to content

Commit bef01f3

Browse files
Ryan Nowakrynowak
Ryan Nowak
authored andcommitted
Blazor API Review: UIEventArgs types
Fixes: #12550 Removes UIEventArgs in favor of EventArgs as the base class. Moving Type into all of our event args types - this is important because many of the events types are used for multiple events. The only think about this that isn't perfect is that we have keep special casing change because of how binding works. I renamed the type to drop the `UI` prefix. It's not possible to define a subclass in the Web project because of the way covariance works (or doesn't work) in .NET.
1 parent 3919dd5 commit bef01f3

33 files changed

+375
-340
lines changed

src/Components/Blazor/Blazor/ref/Microsoft.AspNetCore.Blazor.netstandard2.0.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public partial class WebAssemblyRenderer : Microsoft.AspNetCore.Components.Rende
6262
public override Microsoft.AspNetCore.Components.Dispatcher Dispatcher { get { throw null; } }
6363
public System.Threading.Tasks.Task AddComponentAsync(System.Type componentType, string domElementSelector) { throw null; }
6464
public System.Threading.Tasks.Task AddComponentAsync<TComponent>(string domElementSelector) where TComponent : Microsoft.AspNetCore.Components.IComponent { throw null; }
65-
public override System.Threading.Tasks.Task DispatchEventAsync(ulong eventHandlerId, Microsoft.AspNetCore.Components.Rendering.EventFieldInfo eventFieldInfo, Microsoft.AspNetCore.Components.UIEventArgs eventArgs) { throw null; }
65+
public override System.Threading.Tasks.Task DispatchEventAsync(ulong eventHandlerId, Microsoft.AspNetCore.Components.Rendering.EventFieldInfo eventFieldInfo, System.EventArgs eventArgs) { throw null; }
6666
protected override void Dispose(bool disposing) { }
6767
protected override void HandleException(System.Exception exception) { }
6868
protected override System.Threading.Tasks.Task UpdateDisplayAsync(in Microsoft.AspNetCore.Components.Rendering.RenderBatch batch) { throw null; }

src/Components/Blazor/Blazor/src/Rendering/WebAssemblyRenderer.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ protected override void HandleException(Exception exception)
120120
}
121121

122122
/// <inheritdoc />
123-
public override Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo eventFieldInfo, UIEventArgs eventArgs)
123+
public override Task DispatchEventAsync(ulong eventHandlerId, EventFieldInfo eventFieldInfo, EventArgs eventArgs)
124124
{
125125
// Be sure we only run one event handler at once. Although they couldn't run
126126
// simultaneously anyway (there's only one thread), they could run nested on
@@ -185,10 +185,10 @@ readonly struct IncomingEventInfo
185185
{
186186
public readonly ulong EventHandlerId;
187187
public readonly EventFieldInfo EventFieldInfo;
188-
public readonly UIEventArgs EventArgs;
188+
public readonly EventArgs EventArgs;
189189
public readonly TaskCompletionSource<object> TaskCompletionSource;
190190

191-
public IncomingEventInfo(ulong eventHandlerId, EventFieldInfo eventFieldInfo, UIEventArgs eventArgs)
191+
public IncomingEventInfo(ulong eventHandlerId, EventFieldInfo eventFieldInfo, EventArgs eventArgs)
192192
{
193193
EventHandlerId = eventHandlerId;
194194
EventFieldInfo = eventFieldInfo;

src/Components/Blazor/Build/test/ComponentRenderingRazorIntegrationTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ namespace Test
253253
public class MyComponent : ComponentBase
254254
{
255255
[Parameter]
256-
public Action<UIEventArgs> OnClick { get; set; }
256+
public Action<EventArgs> OnClick { get; set; }
257257
}
258258
}
259259
"));
@@ -263,7 +263,7 @@ public class MyComponent : ComponentBase
263263
264264
@code {
265265
private int counter;
266-
private void Increment(UIEventArgs e) {
266+
private void Increment(EventArgs e) {
267267
counter++;
268268
}
269269
}");
@@ -280,7 +280,7 @@ private void Increment(UIEventArgs e) {
280280
AssertFrame.Attribute(frame, "OnClick", 1);
281281

282282
// The handler will have been assigned to a lambda
283-
var handler = Assert.IsType<Action<UIEventArgs>>(frame.AttributeValue);
283+
var handler = Assert.IsType<Action<EventArgs>>(frame.AttributeValue);
284284
Assert.Equal("Test.TestComponent", handler.Target.GetType().FullName);
285285
Assert.Equal("Increment", handler.Method.Name);
286286
});

src/Components/Blazor/Build/test/RenderingRazorIntegrationTest.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ public async Task SupportsTwoWayBindingForTextboxes()
332332
// Trigger the change event to show it updates the property
333333
//
334334
// This should always complete synchronously.
335-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs { Value = "Modified value", }));
335+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs { Value = "Modified value", }));
336336
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
337337
await task;
338338

@@ -367,7 +367,7 @@ public async Task SupportsTwoWayBindingForTextareas()
367367
// Trigger the change event to show it updates the property
368368
//
369369
// This should always complete synchronously.
370-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs { Value = "Modified value", }));
370+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs { Value = "Modified value", }));
371371
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
372372
await task;
373373

@@ -404,7 +404,7 @@ public async Task SupportsTwoWayBindingForDateValues()
404404
//
405405
// This should always complete synchronously.
406406
var newDateValue = new DateTime(2018, 3, 5, 4, 5, 6);
407-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs { Value = newDateValue.ToString(), }));
407+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs { Value = newDateValue.ToString(), }));
408408
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
409409
await task;
410410

@@ -440,7 +440,7 @@ public async Task SupportsTwoWayBindingForDateValuesWithFormatString()
440440
// Trigger the change event to show it updates the property
441441
//
442442
// This should always complete synchronously.
443-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs { Value = new DateTime(2018, 3, 5).ToString(testDateFormat), }));
443+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs { Value = new DateTime(2018, 3, 5).ToString(testDateFormat), }));
444444
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
445445
await task;
446446

@@ -559,7 +559,7 @@ public async Task SupportsTwoWayBindingForBoolValues()
559559
// Trigger the change event to show it updates the property
560560
//
561561
// This should always complete synchronously.
562-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs() { Value = false, }));
562+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs() { Value = false, }));
563563
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
564564
await task;
565565

@@ -595,7 +595,7 @@ public async Task SupportsTwoWayBindingForEnumValues()
595595
// Trigger the change event to show it updates the property
596596
//
597597
// This should always complete synchronously.
598-
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new UIChangeEventArgs { Value = MyEnum.SecondValue.ToString(), }));
598+
var task = renderer.Dispatcher.InvokeAsync(() => setter.InvokeAsync(new ChangeEventArgs { Value = MyEnum.SecondValue.ToString(), }));
599599
Assert.Equal(TaskStatus.RanToCompletion, task.Status);
600600
await task;
601601

0 commit comments

Comments
 (0)