tschuehly / spring-view-component

Server-side UI components with spring boot
MIT License
208 stars 11 forks source link

Java ViewContext constructors don't accept varargs #13

Closed DaniSalasDev closed 1 year ago

DaniSalasDev commented 1 year ago

Using:

The following snippet fails to compile:

    public ViewContext render() {
        return new ViewContext(
                ViewProperty.of("helloWorld", "Hello World"),
                ViewProperty.of("coffee", "coffee")
        );
    }

The ViewContext constructor doesn't work as expected in Java due to the following reasons:

The solution (attempting to have minimal to no impact for Kotlin APIs) would be the following replacement for ViewContext.kt constructors

    constructor(
            vararg contextAttributes: ViewProperty
    ) : this(contextAttributes)

    constructor(
            componentTemplate: String?,
            vararg contextAttributes: ViewProperty
    ) : this(contextAttributes) {
        this.componentTemplate = componentTemplate
    }

Would have loved to provide a PR with test coverage for the compile error too, but wasn't sure about how to contribute (branch to create from/PR to).

Also, please let me know if providing a sample project would be useful.

tschuehly commented 1 year ago

Hey Dan how are you doing? Thank you very much for you the issue. I'm currently reworking the ViewAttributes in the 0.7.0-SNAPSHOT branch. You can get it like this:

repositories {
    mavenCentral()
    maven {
        url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots/")
        mavenContent {
            snapshotsOnly()
        }
    }
}

dependencies {
    implementation("de.tschuehly:spring-view-component-jte:0.7.0-SNAPSHOT")
    annotationProcessor("de.tschuehly:spring-view-component-core:0.7.0-SNAPSHOT")
}

You can check out an example here: https://github.com/tschuehly/spring-view-component/tree/v0.7.0-SNAPSHOT/examples/thymeleaf-java-example/src

DaniSalasDev commented 1 year ago

Much appreciated!

I still have very little time for side projects, but I at least wanted to take this for a spin.

Funny that you mentioned the 'GitHub developed a similar Library for Ruby on Rails to ease the development of the very site you are on right now', as I'm working on a CRUD and its only exotic feature is a markdown editor like this one.

Will check the new version, and hopefully I can provide more feedback on that :)

Also, on my end it's good if you close this as not planned with the rework.