Closed abedurftig closed 10 months ago
Hey there,
yes I have not tried Kotlin with Maven yet.
You could try out to use the kapt maven plugin instead of the maven compiler plugin: https://kotlinlang.org/docs/kapt.html#use-in-maven
That could maybe fix the issue already, as in gradle-kotlin configuration you need to use the kapt plugin aswell. Should add that to the readme 😄 https://github.com/tschuehly/spring-view-component/blob/ca6d4ccda16299c3b9e4418529188247e288296d/examples/kte-example/build.gradle.kts#L22
Hello. That works. This commit fixes it.
If I understand correctly, then render()
will always return the "full" page or am I mistaken? My understanding is that the idea of HTMX is that you would return a smaller piece of HTML and that would be replaced in the page. Have you thought about sending only the diff?
Great that it works now! Will add it to the docs.
The Idea of ViewComponent is to seperate the page into individual components where you can use composition to build your UI. You would always rerender a whole component. How small a component is up to you. The size of the html sent over the wire is negligible imo.
You can always use OutOfBounds Swap to swap multiple components on the page in a single request. https://htmx.org/attributes/hx-swap-oob/
To send only the diff you would need some kind of information of the current representation on the client which goes against HATEOAS principle. I would advise against that and just let HTMX handle the diffing.
P.S: You can have multiple methods in your component which return the ViewContext implementation.
Hey, thanks for following up. But I think there might be some misunderstandings.
To send only the diff you would need some kind of information of the current representation on the client which goes against HATEOAS principle.
The HATEOAS principal talks about the knowledge the client has of the server, not the other way around. It says: "I should send enough information so the client knows what can be done with the state (ie. which links (actions) are available - by including the links in the HTML for ex.).
But I think the word "diff" is misleading. What I meant that the server is just sending the "relevant" bit (the one which changed). In the counter example, this would be the <h3>X</h3>
(not also sending the button, etc.). Your view-actions need to be very specific.
I would advise against that and just let HTMX handle the diffing.
HTMX does not do any diffing, but just swapping HTML in a target. What view-components
seems to do, is to give the HTML body an id and use that as target.
if (htmlLine.contains("<body")) {
return@map htmlLine.replace("<body", "<body id=\"$viewComponentName\"")
}
By default HTMX targets the element, which triggered the AJAX call, right?
The size of the html sent over the wire is negligible imo.
Maybe. But to stay with the counter example, why not just submit a form then re-load the whole page then? Except "dependencies from the header" maybe.
Maybe this issue is not the place for this kind of discussion. 😄
Anyhow, I will keep playing with view-components
.
Regards
Hey man. Interesting project. 💪
I have tried this with Maven and Kotlin (which seems to be the only case, which is not included in your examples). It seems something is not working. I cannot find the HTML files in the target/classes folder after
mvn clean compile
.I have tried adding the mvn resources plugin to move the HTML files and that kind of works until you want to use HTMX and ViewActions.
I have created a sample project here which reproduces the issue.
It seems that maybe the annotation processor is not running.