Skip to content

Blazor API review changes: CompilerServices #11911

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 2 commits into from
Jul 9, 2019

Conversation

rynowak
Copy link
Member

@rynowak rynowak commented Jul 5, 2019

Fixes: #11907

These are the changes from the compiler-related API review that are safe
to make (these methods are not used).

I'll follow up with BindMethods.GetValue separately because that's
used by the compiler.

@rynowak rynowak force-pushed the rynowak/compiler-api-review branch from 3dbb13e to a376ef4 Compare July 5, 2019 00:34
@rynowak
Copy link
Member Author

rynowak commented Jul 5, 2019

See issue for rationale

/// <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="value">The value of the attribute.</param>
public void AddAttribute(int sequence, string name, Action<UIEventArgs> value)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are unused except for some unit tests. It's still possible to attach arbitrary delegates to the RTB - these methods are here to support method-group-to-delegate conversion and aren't really needed anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's still possible to attach arbitrary delegates to the RTB

But there's no use case for it, is there? Is this what we're discussing above with "should we remove the Action/Func<T> overloads of AddAttribute, or is this something else?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But there's no use case for it, is there?

The only use case for it would be making it nicer for someone writing RTB code by hand. Let's look at this again during the RTB API review.

@rynowak rynowak force-pushed the rynowak/compiler-api-review branch from a376ef4 to f1bfdc4 Compare July 5, 2019 00:39
Fixes: #11907

These are the changes from the compiler-related API review that are safe
to make (these methods are not used).

I'll follow up with `BindMethods.GetValue` separately because that's
used by the compiler.
@rynowak rynowak force-pushed the rynowak/compiler-api-review branch from f1bfdc4 to 2d8437c Compare July 5, 2019 00:41
{
HandlerWasCalled = true;
}
}");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@SteveSandersonMS - speakup if you have concerns. I'm specifically removing support for things like this (not using directive attributes). Should we do this with Action and Func<Task> as well?

Copy link
Member

@SteveSandersonMS SteveSandersonMS Jul 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I expect this is fine, including removing the Action/Func<Task> variants too. The ideal, if we have time for it, would be issuing a compile-time warning for people who put attributes named onX with delegate-type values when they fail to use the directive attribute.

I just checked that our extensibility for event tag helpers works nicely (it does), so people are free to define their own custom event type names and values. This is essential because the HTML spec continues to evolve, and new or nonstandard event names will keep appearing.

Given that the tag helper extensibility works well, there's no use case for people trying to define events handlers any other way. The only risk is that they don't know about how to do it, which is where a compiler warning (perhaps with a fwlink to docs) would be ideal. If we don't have time to add the warning now, it could be added in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we don't have time to add the warning now, it could be added in the future

I'm not certain how this would work in practice. We don't know in the Razor compiler what kind of value you're passing in when you set an attribute.

{
// Arrange
var builder = new RenderTreeBuilder(new TestRenderer());

// Act/Assert
Assert.Throws<InvalidOperationException>(() =>
{
builder.AddAttribute(0, "name", eventInfo => { });
builder.AddAttribute(0, "name", new Action<UIEventArgs>(eventInfo => { }));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify why this change is here? The test name only talks about delegates in general, not specific types of delegates. So why wasn't the previous code sufficient to represent that?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is needed to make the type conversion work. I tried to keep the semantics of what's being tested the same.

Copy link
Member

@SteveSandersonMS SteveSandersonMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've posted a few questions, but it looks like you're all over this.

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label Jul 8, 2019
@danroth27 danroth27 mentioned this pull request Jul 8, 2019
20 tasks
@rynowak rynowak merged commit 6978590 into master Jul 9, 2019
@ghost ghost deleted the rynowak/compiler-api-review branch July 9, 2019 03:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blazor API Review: Compiler Services
3 participants