dotnet / AspNetCore.Docs

Documentation for ASP.NET Core
https://docs.microsoft.com/aspnet/core
Creative Commons Attribution 4.0 International
12.64k stars 25.29k forks source link

Provide motivation for bind modifiers #28254

Closed guardrex closed 1 year ago

guardrex commented 1 year ago

Per @lonix1 on original issue #28245 ...

In this section it says:

For two-way data binding in ASP.NET Core 7.0 or later, we recommend using @bind:get/@bind:set modifiers. For more information, see the @bind:get/@bind:set in the opening section of this article.

But it doesn't say why? I assume that the new v7 syntax allows one to perform a "set" with an async method, which cannot be done using a regular c# (sync) property setter. That is useful, for e.g., when doing autocomplete. Maybe there are other reasons?

Cross-references:


Document Details

Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.

guardrex commented 1 year ago

@lonix1 ... It looks like from Javier's remarks that only one specific reason ... well, that's obvious anyway because dev issues that were opened for the PU aren't listed in the design issue ... the one specific reason that applies to the remark is ...

Or, if you @bind to a property with a get/set pair, you have to discard the Task returned by ValueChanged.InvokeAsync.

Cross-ref: https://github.com/dotnet/aspnetcore/issues/39837

... noting that the example in THIS article's section doesn't bind to a property ... we do it down in the Bind across more than two components section ... which actually has a whole different approach with @bind:get/@bind:set commented out that nobody can see due to problems with the feature at the time of .NET 7's release that were partially fixed by a framework patch and will be completely fixed in VS for the February VS release. The update to that doc section is tracked by a separate issue, which I'll work as soon as the new VS drops and the PU confirms that VS is cool ... the problem in VS btw AFAIK was just that IntelliSense is tripping up on the syntax. I think the runtime is cool ... I think it's just a UI problem in VS.

I think that I should say in the NOTE the one reason that we do have ☝️. Let's do that. I'm not convinced that we should cross-link the whole design issue at this point. I'll take more feedback on that. If more devs ask about the motivations for the change and want to read further, I'll give them the link to that PU issue at first ... and if folks keep asking, I'll cross-link that PU issue into the document in the earlier section that introduces the main concepts.