flow icon indicating copy to clipboard operation
flow copied to clipboard

LitRenderer withProperties method to optimize code

Open oliveryasuna opened this issue 1 year ago • 5 comments

Describe your motivation

Say I have a grid that uses the following record:

public record Rectangle(double width, double height) {}

And I want to add a column that uses LitRenderer:

grid.addColumn(
    LitRenderer
        .<Rectangle>of("<span class=\"${item.class}\">${item.text}</span>")
        .withProperty("class", item -> {
         // Some logic that checks both `width` and `height`.
        })
        .withProperty("text", item -> {
         // Same logic.
        })
);

Even though I perform the same logic, I have to do it twice.

Describe the solution you'd like

LitRenderer#withProperties

LitRenderer
    .<Rectangle>of(...)
    .withProperties("class", item -> {
      // Some logic that checks both `width` and `height`.
      // Returns maybe a JSON object with property's `class` and `text`.
    })

Perhaps this could be expanded further to support a single method for both properties and functions.

I feel that component renderers are not a solution as they are troublesome for large datasets.

oliveryasuna avatar Jan 18 '24 01:01 oliveryasuna

@mshabarov Not a big deal, but does the "Good First Issue" label refer to it being my first issue or a good first issue for a new developer? If the former, this is my not first Vaadin issue.

oliveryasuna avatar Jan 24 '24 14:01 oliveryasuna

@oliveryasuna these labels simply means that we in Vaadin Flow appreciate any contribution for it and our estimation is that it should be relatively easy for external developers to implement it. No matter if you've done any other contributions in past or if it's your first one :)

mshabarov avatar Jan 24 '24 14:01 mshabarov

@oliveryasuna these labels simply means that we in Vaadin Flow appreciate any contribution for it and our estimation is that it should be relatively easy for external developers to implement it. No matter if you've done any other contributions in past or if it's your first one :)

Understood, thank you for clarifying. Just a tedious question.

oliveryasuna avatar Jan 24 '24 14:01 oliveryasuna

I'm not sure how this could be implemented without breaking getValueProviders() since the names of the available properties would only be known after running the new type of value provider and seeing what properties were included in its return value. This also makes me believe this isn't an easy issue for someone to get started with contributing.

Legioth avatar Feb 13 '24 15:02 Legioth

@Legioth Funny you mention that. I attempted this, but realized the same, and was coming here to suggest we remove the "Good First Issue" label.

oliveryasuna avatar Feb 29 '24 02:02 oliveryasuna