Replies: 3 comments 3 replies
-
Yes and no. It depends. I do not like large components/single file, I like things small as they are generally easier to understand. But things that logically fit together, e.g. like the toggle button in a row in a table, or more generally, things that do not make sense on their own, I like to stay together with the content where they do make sense.
Exactly. An "addressable fragments" is just a component with a
What you are describing is a component. Components have names and take parameters. This is the advantage of the component model vs. more procedural template languages.
Completely agree.
Absolutely. We need to create our own Luckily, that is not a tall mountain to climb. We need to copy the Feel free to create an issue for this, or even take a step at an implementation. |
Beta Was this translation helpful? Give feedback.
-
Sounds good. I'll work on this tomorrow morning.
…On Tue, May 7, 2024, 7:35 PM Egil Hansen ***@***.***> wrote:
One of the aspects you mentioned was liking everything inside a single
file/component.
Yes and no. It depends. I do not like large components/single file, I like
things small as they are generally easier to understand. But things that
logically fit together, e.g. like the toggle button in a row in a table, or
more generally, things that do not make sense on their own, I like to stay
together with the content where they do make sense.
As I started drawing up what addressable fragments might look like it
started looking more or less like pseudo-components. That's where with
Blazor being component-based to begin with you can't necessarily follow the
same patterns as some of the other template fragment libraries might.
Exactly. An "addressable fragments" is just a component with a @page
directive, or, just a component that other components can reference. To me,
this is a component that makes sense on its own, and can potentially be
used in multiple different contexts. One example of that would be the
ContactEditForm
<https://github.com/egil/Htmxor/blob/examples-project/samples/HtmxorExamples/Components/Pages/Examples/UpdatingOtherContent/ContactEditForm.razor>
here in the samples. It makes sense by itself, but can easily be leverage
by other components/pages too.
The other template fragment approaches give each fragment a name and you
can pass parameters that can be specifically used by that fragment.
What you are describing is a component. Components have names and take
parameters. This is the advantage of the component model vs. more
procedural template languages.
It doesn't make sense to try to do this with Blazor, so it's probably best
if you need to go this route to break things into individual components
where necessary. I think your solution will cover a lot of use cases.
Completely agree.
Would it still be possible to render out Htmxor pages with something akin
to RazorComponentResult using the Htmxor renderer? If there are differences
between what RazorComponentResult renders and what Htmxor renders I would
love to see something like an HtmxComponentResult.
Absolutely. We need to create our own HtmxorComponentResult type, since
RazorComponentResult is hardcoded to use EndpointRenderer indirectly
through RazorComponentResultExecutor. EndpointRenderer is one of the key
components that have been replaced in Htmxor.
Luckily, that is not a tall mountain to climb.
We need to copy the RazorComponentResult.cs
<https://source.dot.net/#Microsoft.AspNetCore.Components.Endpoints/Results/RazorComponentResult.cs>
file, and rename it to HtmxorComponentResult. It has a dependency on
RazorComponentResultExecutor.cs
<https://source.dot.net/#Microsoft.AspNetCore.Components.Endpoints/Results/RazorComponentResultExecutor.cs>
which we also need to copy and name something like
HtmxorComponentResultExecutor.
Feel free to create an issue for this, or even take a step at an
implementation.
—
Reply to this email directly, view it on GitHub
<#39 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAUHLRAOI5PMDY27VK7ZDADZBFQNZAVCNFSM6AAAAABHL3B2JOVHI2DSMVQWIX3LMV43SRDJONRXK43TNFXW4Q3PNVWWK3TUHM4TGNBXHE3DA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I want to really highlight the point that template fragments are not a silver bullet, but it is a very nice bullet to have for specific scenarios. The "Toggle Contact" example is a really good scenario for template fragments, the toggle button fragment feels natural to have directly in the page component: The "Updating Other Content - Triggering Events" I prefer just making the "ContactEditForm" directly addressable as a page. It makes sense to have the form directly addressable, very much in line with REST principles. Created an updated example that shows that; these are the relevant files: This is the changed part from the original TiggeringEvents.razor: You will notice that in This component just wraps the existing reusable |
Beta Was this translation helpful? Give feedback.
-
I'm starting this as a new discussion because the other discussion is a bit busy as is. One of the aspects you mentioned was liking everything inside a single file/component. As I started drawing up what addressable fragments might look like it started looking more or less like pseudo-components. That's where with Blazor being component-based to begin with you can't necessarily follow the same patterns as some of the other template fragment libraries might. The other template fragment approaches give each fragment a name and you can pass parameters that can be specifically used by that fragment.
It doesn't make sense to try to do this with Blazor, so it's probably best if you need to go this route to break things into individual components where necessary. I think your solution will cover a lot of use cases.
Would it still be possible to render out Htmxor pages with something akin to RazorComponentResult using the Htmxor renderer? If there are differences between what RazorComponentResult renders and what Htmxor renders I would love to see something like an HtmxComponentResult.
Source generators might be the best answer to create template fragments someday, but as long as you can't chain source generators that's going to be on pause for at least the current C# version.
Beta Was this translation helpful? Give feedback.
All reactions