-
Notifications
You must be signed in to change notification settings - Fork 191
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
Add @code directive support for Blazor #527
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oo fancy. I have mixed feelings about having @code
and @functions
simultaneously available in component files but I think overall it's a good option to have so we're not completely different from classic Razor.
What sort of problems? |
Hello World
@functions { // Some code 1 }
@code { // Some code 2 }
@functions { // Some code 3 } assuming functions directive pass runs first followed by code directive pass the above will be transformed into,
Note the change in the ordering. This could potentially cause problems. |
I could see that being an issue for extremely large Razor documents and to me what makes it a corner case is the intermingling of So ya, I agree with you that it's a weird corner case. Assuming it's a minor amount of work to implement your idea of adding warnings/restrictions. Which would you do? |
Exactly. Which is why I was wondering if we should enforce that in some way.
I think the easiest thing to do to avoid this completely is to merge functions and code directive passes into one. |
Sounds fine to me. Would keep the logic consistent amongst the two yet still give us opportunities to diverge the functionality in the future if we want. Only thing to watch out for is we'd need to support users registering just one of the directives (or both) manually so we'd need to be sure that scenario works. |
d7883bd
to
c5a7e9e
Compare
🆙 📅 |
|
||
namespace Microsoft.AspNetCore.Razor.Language.Components | ||
{ | ||
public static class ComponentCodeDirective |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Name this CodeDirective
and the Register
below as RegisterForComponents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm just following the same pattern as other component directives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I see, didn't realize we did that. Leave for now then, something we should revisit for all of the component like directives before RTM
} | ||
|
||
// Now we have all the directive nodes, we want to add them to the end of the class node in document order. | ||
var orderedDirectives = directiveNodes.OrderBy(n => n.Source?.AbsoluteIndex); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
Fixes dotnet/aspnetcore#6361
@code
directive that has the exact behavior as@functions
Note:
@functions
directive support in Blazor.